Code: Select all
(module "macro.lsp")
(define-macro (DO-UNTIL test B)
(do-while (not (eval test)) (eval B)))
(macro (DO-UNTIL* T B)
(do-while (not T) B))
(println "test 1")
(define (foo k)
(DO-UNTIL (<= k 0) (begin (println k) (dec k))))
(foo 3)
(println "test 2")
(define (foo* k)
(DO-UNTIL* (<= k 0) (begin (println k) (dec k))))
(foo* 3)
(println "test 3")
(define (bar*)
(let (k 0)
(DO-UNTIL* (>= k (args 0)) (begin (println k) (inc k)))))
(bar* 3)
(println "test 4")
(define (bar)
(let (k 0)
(DO-UNTIL (>= k (args 0)) (begin (println k) (inc k)))))
(bar 3)
Second problem: bar doesn't work at all, because (args 0) is evaluated in the context fo the macro DO-UNTIL.
Those kind of problems makes it really tricky to use fexprs. On the other hand, rewrite macros provided by macro.lsp don't have these problems, and are also faster because the substitution is done at compile-time. They however increase the code size, but this can be mitigated by factoring out the "big parts" of macros in external functions.
macro.lsp notes that it increases the load-time of scripts. Is the impact significant? What about native and improved support for rewrite macros?