3 ms·
A lot of the stuff presented here is mainstream practice in Tcl (e.g., new constructs, dbg evaluation). Tcl is seriously underappreciated language. In my progr
by psranga 17y ago
A lot of the stuff presented here is mainstream practice in Tcl (e.g., new constructs, dbg evaluation). Tcl is seriously underappreciated language.
In my programming whenever I see myself writing blubber (I like that word), I just factor it out into a separate procedure and give it a descriptive name.
So when I'm reading the code of the calling routine, I rarely see blubber; it's contained in simple routines that are easy to read/verify.
Most of the examples here amount to thoughtful library development. With a good library, C++ and macro processor can also many of these things.
Here's a version of aif that works for most cases (I'm not claiming that C has the expressive power of Lisp):
#define aif(expr, val, code...) \
{ if ((expr) != (val)) { \
code ; \
} \
}
IMHO, this is good enough for blubber reduction.
- dreish 17y agoThat's not aif at all. In fact, you can't even do it for "most cases" in C because you don't know what type expr will evaluate to, but if we could cheat and assume it will be an int: #define aif(expr, code) \ { \ int it = (expr); \ if (it) \ { \ code; \ } \ } But this is still not close because in a Lisp, if is an expression that returns a value. We can't use the ternary operator because then there's no place to declare the "it" variable. You can't have an expression that declares a variable local to that expression in C no matter how hard you try. And the above lacks the "do {} while (0)" weirdness needed to make a cpp macro behave syntactically roughly like a function.
- psranga 17y agoI agree. My bad. I appreciate the clarificaiton.