|
|
|
|
|
by kazinator
1551 days ago
|
|
We know from Lisp that, for instance, you can write a while loop like this. (defmacro while (condition &rest body)
`(let ((cond-fun (lambda () ,condition))
(body-fun (lambda () ,@body))
(while-macro-run-time-function cond-fun body-fun)))
Then we have a run-time support function: (defun while-macro-run-time-function (cond-function body-function)
(loop while (funcall cond-function)
do (funcall body-function)))
Closures allow macros to parcel off expressions or bodies of expressions into functions, so that control structures can then be made "remote": put into a function.This has the benefit of keeping expansions small. Another benefit is that since the core logic is in the run-time function(s), those can be updated to fix something without having to recompile the macro invocations. Somehow, the sky doesn't fall in Lisp land; we don't need articles like, OMG I learned about this in 2018 and it's so dangerous. |
|
I see a difference with hooks, where you need a linter to verify that you used them as intended: they must start with useSomething and be called in the top level. As opposed to use native language features.