[racket] anamorphic macros
Hi all,
I was working through chapter 16 of "land of lisp" and there is (at that
point) a buggy split macro defined like this:
(defmacro split (val yes no)
`(if ,val
(let ((head (car ,val))
(tail (cdr ,val)))
,yes)
,no))
Here is my version of the equivalently buggy Racket counterpart:
(define-syntax split
(syntax-rules ()
([split val yes no]
(eval
'(if (empty? val)
no
(let ([head (car val)]
[tail (cdr val)])
yes))))))
Calling the macro works as intended (ignoring the multiple evaluation of
"val" in this buggy version):
(split (list 1 2 3 4 5 6) tail #f)
;; => (2 3 4 5 6)
Now to my question: is there a way to make head and tail visible without
resorting to the eval-quote combination?
In other words, is there a more Racket-like way to achieve the same?
Cheers,
Peter