-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How is cond
supposed to work?
#655
Comments
Well, I wrote one from scratch that words for me and expands correctly
(def caseOf
(macro (cases)
(if (isEmpty cases)
:nil
(let ( (this_case (nth cases 0))
(case_cond (nth this_case 0))
(case_then (nth this_case 1)))
`(if ~case_cond
~case_then
(caseOf ~(rest cases))))))) Seems to work well:
Anyone see any issues with that? Also, still eager to learn what I was missing about MAL's own |
Update: only now noticed that MAL's (def cond
(macro (& xs)
(if (> (count xs) 0)
(list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs))))))) still results in a stack overflow with 2 args or more 😵💫 my own |
First off, love this project and having a blast with progressing through it! 🎉
Well, after the first 8 chapters, I now got all the macro, quasiquotation etc tests working except for
cond
tests: expansion ofcond
(even just by doingmacroexpand
in REPL) will have myif
special-form (that the macro body is clearly calling) erroring on wrong arg count (2 instead of 3).And no wonder, looking at
cond
as defined inprocess/step8_macros.txt
, just indented:The
if
has no "else-branch arg" (the 3rd).Now what? I must be missing something here?
For reference, here are my macroexpand and eval and quasiquote/unquote.
Like I said, all tests of steps 1 through 8 succeed, except the cond stuff.
The text was updated successfully, but these errors were encountered: