Last active
August 29, 2015 14:06
-
-
Save rentalcustard/d83cf7bd4805512c90d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro new-if [pred then-clause else-clause] | |
`(cond ~pred ~then-clause | |
:else ~else-clause)) | |
"This works, in that if I call it like so: | |
" | |
(new-if (= 2 3) (while true (print "hi")) :bye) | |
"I don't get an infinite loop, but I don't understand how. I've unquoted | |
everything in the macro body, so shouldn't the normal evaluation order | |
apply? Why doesn't it evaluate then-clause when I do it this way? | |
" |
I think I'll have more luck doing it with Scheme's define-syntax
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"if" is a special form with custom evaluation order. Usually people write macros in terms of "if" (or other things built on if like cond) to show how to write new syntax with delayed evaluation.