Skip to content
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

if-let's else branch appears multiple times in its expansion #1191

Closed
ianthehenry opened this issue Jun 11, 2023 · 1 comment · Fixed by #1190
Closed

if-let's else branch appears multiple times in its expansion #1191

ianthehenry opened this issue Jun 11, 2023 · 1 comment · Fixed by #1190

Comments

@ianthehenry
Copy link
Contributor

This is unrelated to the recent if-let changes -- if-let has always worked this way, but I found this very surprising:

repl:1:> (defmacro hello [] (print "hello") 1)
<function hello>
repl:2:> (if-let [a true] "ok" (hello))
hello
"ok"
repl:3:> (if-let [a true b true] "ok" (hello))
hello
hello
"ok"
repl:4:> (if-let [a true b true c true] "ok" (hello))
hello
hello
hello
"ok"

I would expect the else branch to only appear once in the expansion of if-let -- which I believe is not compatible with the desire to be able to reference the first binding form in the else branch.

@primo-ppcg
Copy link
Contributor

primo-ppcg commented Jun 11, 2023

It could also be implemented differently. Since we've already touched it, it may be worth addressing.

which I believe is not compatible with the desire to be able to reference the first binding form in the else branch.

It's not. Not expanding macros with side-effects more than once is more desirable and correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants