2010/05/25

syntax-rules: quoted-append

;; quoted-append
(define-syntax quoted-append
(syntax-rules ()
((_)(append))
((_ lis)
(append (quote lis)))
((_ lis1 lis2)
(append (quote lis1)(quote lis2)))
((_ lis1 lis2 ...)
(append (quote lis1)(quoted-append lis2 ...)))))
(quoted-append (1 2 3) (4 5) (+ x y))
; -> (1 2 3 4 5 + x y)
(quoted-append (1 2 3))
; -> (1 2 3)
(quoted-append (1 2 3)(+ 4 5)(+ 6 7 8)((lambda(x)(* x x)) 4) )
; -> (1 2 3 + 4 5 + 6 7 8 (lambda (x) (* x x)) 4)
(quoted-append)
; -> ()


追記

何か違う気がする。こういう意図じゃないような気がする。

プログラミングGauche

0 件のコメント:

コメントを投稿