3 ms·
OK, but I've been aware of Lisp macros for a while, and still never seen a situation where I needed them. A couple weeks ago, though, I found myself in a situa
by AnimalMuppet 12y ago
OK, but I've been aware of Lisp macros for a while, and still never seen a situation where I needed them.
A couple weeks ago, though, I found myself in a situation where the user needed to be able to specify a filter, and the filter was going to be a tree of expressions, and the program had to take what the user specified and turn it into something the program could execute... and the filter tree looks a lot like an S-expression... hmm...
So I'm seeing something that could be done much easier in Lisp. It's still not a need for a macro, though (unless you're going to suggest that I use a macro to turn some user-writeable DSL into Lisp, and sure, it could be done that way.)
- marktangotango 12y agoI'm not a lisper either, but I think the key idea, and I've looked but can't find the reference for this, is expanding the language space to intersect the problem space. Any given language has a domain of problems it's suited to: manipulating number, strings, objects with loops and conditionals and organizing code with data (oop). This is the language domain. Then users (programmers) create abstractions with the language to represent a problem domain (payment processing, cms, reddit, whatever). The idea with macros is to extend the syntax of the language to move the entire language to the problem domain, for example the html generating dsl pg and company used at viaweb (see his writing). This distinction is not as profound today, imo, because languages have come a long way. Php didn't exist when pg and friends were doing viaweb, today templating html is old hat, but at the time specifying a dsl in lisp macros to dyanmcically generate html was quiet innovative.
- silverlake 12y agoEveryone here is hoping their favorite language feature will added to Java 9, Python 3, C++14, Javascript, etc. Whatever feature that is, Lisp programmers would add it with a macro and move on. There is no central governing body deciding what I can or can't do with the language syntax. That's why macros are useful.