5 ms·
Here is a version that follows the Common Lisp solution. Since `reduce` is the standard library of Common Lisp, I implemented the case I needed. #lang rack
by soegaard 4y ago
Here is a version that follows the Common Lisp solution.
Since `reduce` is the standard library of Common Lisp,
I implemented the case I needed.
#lang racket
#;(defmacro nest (&rest r)
(reduce (lambda (o i) `(,@o ,i)) r :from-end t))
(begin-for-syntax
(require racket/match)
(define (reduce f xs)
(match xs
[(list x0 x1) (f x0 x1)]
[(cons a d) (f a (reduce f d))])))
(define-syntax (nest r)
(reduce (λ (o i) #`(#,@o #,i))
(cdr (syntax->list r))))
(nest
(list 'foo)
(list 'bar)
(list 'baz)
'qux)