Skip to content

Instantly share code, notes, and snippets.

@valvallow
Created June 9, 2010 08:42
step, scheme, syntax,
(define-syntax hoge
(syntax-rules ()
((_ x)
(hoge "hoge" x))
((_ "hoge" x)
(let ()
(print x)
(print "hoge")))))
(hoge 'valvallow)
;; valvallow
;; hoge
;; #<undef>
(macroexpand '(hoge 'valvallow))
;; (#<identifier user#let> ()
;; (#0=#<identifier user#print> 'valvallow)
;; (#0# "hoge"))
(hoge "hoge" 'valvallow)
;; valvallow
;; hoge
;; #<undef>
(macroexpand '(hoge "hoge" 'valvallow))
;; (#<identifier user#let> ()
;; (#0=#<identifier user#print> 'valvallow)
;; (#0# "hoge"))
(hoge "hoge")
;; hoge
;; hoge
;; #<undef>
(macroexpand '(hoge "hoge"))
;; (#<identifier user#let> ()
;; (#0=#<identifier user#print> "hoge")
;; (#0# "hoge"))
(define (p l1 l2)
(format #t " x:~a - y:~a\n" l1 l2))
(define-syntax print-reverse-list
(syntax-rules ()
((_ (x ...))
(print-reverse-list "sub" (x ...)()))
((_ "sub" (x1 x2 ...)())
(begin
(p '(x1 x2 ...)())
(print-reverse-list "sub" (x2 ...)(x1))))
((_ "sub" (x1 x2 ...)(y ...))
(begin
(p '(x1 x2 ...)'(y ...))
(print-reverse-list "sub" (x2 ...)(x1 y ...))))
((_ "sub" (x)(y1 y2 ...))
(print-reverse-list "sub" ()(x y1 y2 ...)))
((_ "sub" ()(y ...))
(p '() '(y ...)))))
(print-reverse-list (1 2 3 4 5))
;; x:(1 2 3 4 5) - y:()
;; x:(2 3 4 5), y:(1)
;; x:(3 4 5), y:(2 1)
;; x:(4 5), y:(3 2 1)
;; x:(5), y:(4 3 2 1)
;; x:(), y:(5 4 3 2 1)
;; #<undef>
(print-reverse-list (1))
;; x:(1) - y:()
;; x:(), y:(1)
;; #<undef>
(print-reverse-list ())
;; x:(), y:()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment