3 ms·
> You can look at some lisp code and have no idea of what it does if you don't expand a few layers of macros first. I've not once expanded a macro in order to
by travv0 6y ago
> You can look at some lisp code and have no idea of what it does if you don't expand a few layers of macros first.
I've not once expanded a macro in order to see what it does. The only reason I can think of that one would do that is to see how it works, but one also has to look at e.g. the definition of a function to see how that function works, and that should almost never be important. How are macros different? Just like functions, one often has to read the documentation to know how to use a macro, but I'm not sure how being a macro makes (loop for i from min to max do ...) harder to read than a function would be.
- simias 6y agoFunctions can be opaque of course, but macros are worse because anything goes. I think the standard loop macro is a good example of this: (loop repeat 10 for x = (random 100) if (evenp x) collect x into evens else collect x into odds finally (return (values evens odds))) This macro is actually fairly well designed, so you can guess what all of this does just by interpreting the names (assuming that you understand English well at least) but it's barely Lisp. Just figuring out what parts of this call are keywords and what part are just normal symbols is hard to figure out. (return ...) looks like a function call, but I don't think it is(?). Is collect a loop-ism or can I replace it by any function name? I think it's the former. Is "into" just here to make grammatical sense or are there other keywords I can use here? If `evens` and `odds` already exist as variable names outside of the loop, will they be used or is it a new local binding? If it is a local binding, how do I tell it to use some existing variable name instead? Basically it's like printf format strings, it's a language within a language, and idiomatic Common Lisp is often full of that stuff in my experience.
- AnimalMuppet 6y ago> Basically it's like printf format strings, it's a language within a language... That's to be expected with a DSL, isn't it? It's almost the definition. But I think you're right. The point of a DSL is to change the language to something that you find more useful for what you're trying to do. The downside is that you've changed the language, and now people don't know what to expect unless they're very familiar with your DSL.