M-99 マクロ99問
http://common-lisp-users.jp/index.cgi?M-99
問3:Common LispのWHENを作成せよ
テーマ:制御構文の自作
(my-when (< 1 2) (print "hello")) ;-> ; "hello" ;=> "hello"
解3:
CL-USER> (defmacro my-when (condition &rest body)
`(if ,condition
(progn ,@body)))
MY-WHEN
CL-USER> (my-when (> 2 1)
(print "hello1")
(print "hello2"))
"hello1"
"hello2"
"hello2"
CL-USER> (my-when (< 2 1)
(print "hello1")
(print "hello2"))
NIL
補足3:展開されたS式
(IF (< 2 1)
(PROGN (PRINT "hello1") (PRINT "hello2")))
0 件のコメント:
コメントを投稿