3 ms·
Extending a language with macros isn't all that different from extending a language with your own functions. At least in principle. And a lot of what tends to
by eru 4y ago
Extending a language with macros isn't all that different from extending a language with your own functions. At least in principle.
And a lot of what tends to be macros in Lisp turns into functions in eg Haskell. Eg you can define your own new branching and looping constructs (like 'if' or 'while') etc as functions in Haskell, but in Lisp these need to be macros.
- reikonomusha 4y agoUnlike call-by-need evaluation, macros provide the opportunity to compute things at compile time (think lookup tables) or analyze the arguments at compile time (think DB query syntax checking). In Lisp, you can also define branching and looping as functions, but you need to concede and have the arguments themselves be (lambda) functions. (defun while (c body) (when (funcall c) (funcall body) (while c body)))
- eru 4y agoYes, I know that laziness doesn't take care of all macros. That's why even Haskell has macros. Yes, if you wrap your arguments in lambdas, you can write loops like that. Though to be as performant as the built-in constructs, you need a rather clever compiler that 'removes' the lambdas again.