3 ms·
This is an bad example of macros; they're completely unnecessary here. The only thing you're stepping around is the already reader-macro shortened (function <).
by spacemanaki 15y ago
This is an bad example of macros; they're completely unnecessary here. The only thing you're stepping around is the already reader-macro shortened (function <). If you want to show off macros I think you should do it with something that simply cannot be done without them. Otherwise you end up with these pissing matches in the comments and the discussion diverges entirely away from metaprogramming to talking about characters or lines of code saved, which is kind of not that interesting. And Java vs Lisp is already kind of a tired topic. (Lisper and card carrying Java-hater here)
- mck- 15y agoI agree, and I am aware of it. I was about to get into another example to show something that only macros can do, but the post was getting too long. So please hang in there ;) I'm getting there. Also, there are different levels of audience. Diving straight into complex macro structures might just be ineffective. Above all, I'm not trying to preach to the converted. You seem to be well aware of the powers of Lisp, so not my intended audience. But thanks for reading and your input anyway ;)
- jwhite 15y agoI agree with spacemanaki. Your article introduces higher order functions, which is a big enough concept to keep those unfamiliar well-entertained without going a step too far and throwing in a not-particularly-useful macro. The last part of the article is an un-illuminating distraction. If I wasn't familiar with CL I would probably be scratching my head and asking why the hell that ugly #' is needed in the first place. More seriously though, your macro is dangerous as a teaching example because it introduces variable capture (on i and ans) and unintentional repeated evaluation (of list), which are big gaping traps for the unwary. Also, try passing #'(lambda (a b) (< a b)) as the pred argument to your macro, and see what happens.