èªå®¶è£½quasiquote
俺Lispã®unquoteãã対å¿ãã¦ããªãã£ãquasiquoteãunquote-splicingã«ã対å¿ããã¦ã¿ãã
and,or,condçã®åºæ¬ãã¯ãã®å®ç¾©ã«ãquasiquoteã使ããããã«ãquasiquoteèªä½ã®å®ç¾©ã«ã¯ãããã¯ä½¿ããã«ä»¥ä¸ã§ä»£ç¨ã
(and x y) â (if x y #f)ã§ä»£ç¨ã
(or x y) â (if x #t y)ã§ä»£ç¨ã
(cond ...) â ifã®å
¥ãåã§ä»£ç¨ã
(define-macro (quasiquote x) (if (not (pair? x)) (list 'quote x) (if (if (eq? (car x) 'unquote) #t (eq? (car x) 'unquote-splicing)) (cadr x) (list (if (if (pair? (car x)) (eq? (car (car x)) 'unquote-splicing) #f) 'append 'cons) (list 'quasiquote (car x)) (list 'quasiquote (cdr x))))))
ä½ã£ã¦ã¿ã¦ããã£ããã ãã©ã`(a b ,@x)ã¨æ¸ãã¦ããé¨åã¯ã`(a b . ,x)ã¨æ¸ãã¦ãåããã¨ã«æ°ãã¤ããã
ããã£ã¦ã,xã®å®ä½ã¯(unquote x)ã¨ãããªã¹ãã ãããå
¨ä½ã¯(quasiquote (a b unquote x))ã¨ãªã£ã¦ããããã ã
ã¢ã«ã´ãªãºã çã«ã¯ããã£ã¦ãã¦ããè¦ãç®çã«unquoteãå
é è¦ç´ ãããªããªã¹ãä¸ã«åããã¦ããã®ã«åãã®ã£ã¦ãããããã
repl> `(a b . ,(list 1 2))
http://kar.s206.xrea.com/lisp/?e=%60(a%20b%20.%20%2C(list%201%202))
(a b 1 2)
repl> '`(a b . ,(list 1 2))
http://kar.s206.xrea.com/lisp/?e=%27%60(a%20b%20.%20%2C(list%201%202))
(quasiquote (a b unquote (list 1 2)))
Gaucheã§ãåãåä½ã ã£ãã
gosh> `(a b . ,(list 1 2)) (a b 1 2) gosh> '`(a b . ,(list 1 2)) `(a b unquote (list 1 2))
ãããæ¬å½ã¯å ¥ãåã対å¿ããªãã¨ãããªãã®ãã
R6RS:翻訳:R6RS:11.17 Quasiquotation
quasiquote ãã©ã¼ã ã¯å ¥ãåã«ãããã¨ãã§ãããç½®ãæãã¯ä¸çªå¤å´ã® quasiquote ã¨åãå ¥ãåã¬ãã«ã®é¨åã«ç¾ãã unquote ãããè¦ç´ ã«ã ãè¡ããããå ¥ãåã¬ãã«ã¯ãããã次㮠quasiquote 㧠1 å¢å ãã unquote ã®å å´ã§ 1 æ¸å°ããã`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f) â (a `(b ,(+ 1 2) ,(foo 4 d) e) f)http://practical-scheme.net/wiliki/wiliki.cgi?R6RS%3A%E7%BF%BB%E8%A8%B3%3AR6RS%3A11.17%20Quasiquotation