"Backquote" syntax
muSE does not support the Scheme/Lisp backquote notation in its reader. This is primarily because I was lazy, but later on I realized that it is simple to implement something like it using muSE's macro facility. Here's the definition -
(define literal
(fn 'args
(case args
(()
())
((('unlit expr) . etc)
(list 'cons expr (apply literal etc)))
((('unlit-splice expr) . etc)
(list 'append! expr (apply literal etc)))
((x . etc)
(list 'cons (cons quote x) (apply literal etc))))))
For example -
(literal 1 2 (+ 1 2)
(unlit (+ 2 2))
(unlit-splice (map (fn (x) (* x x)) '(5 6 7)))
8 9 10)
will get you the literal expression -
(1 2 (+ 1 2) 4 25 36 49 8 9 10)
This works mostly well enough to write macros using it, except when you want to use a macro-like expression within the literal, in which case the result of the macro expansion will be used instead of the literal macro term. This is due to the tail-first expansion performed by muSE.
No comments:
Post a Comment