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

Double evaluation in SET due to lowering #225

Open
shawwn opened this issue Mar 25, 2022 · 0 comments
Open

Double evaluation in SET due to lowering #225

shawwn opened this issue Mar 25, 2022 · 0 comments

Comments

@shawwn
Copy link
Contributor

shawwn commented Mar 25, 2022

I ran across an interesting one. It's not immediately clear how to solve it:

> (set x (set (get (or (print 'foo) (obj)) 'a) 42))
foo
foo

The problem is that "foo" should only be printed once, but it's being printed twice here.

You can get a clearer idea of the issue by looking at the compiled output:

> (print (compile (expand '(set x (set (get (or (print 'foo) (obj)) 'a) 42)))))
(print("foo") or {}).a = 42
x = (print("foo") or {}).a

I made a couple attempts at solving this by modifying lower-set, but I haven't been able to come up with a solution at all, let alone a solution that's simple.

I think it's necessary to check whether the left-hand side expression starts with (get ...), since I'm not sure there's another situation where this can arise. But it feels odd to special case it like that.

It's possible this might not be a bug at all -- emacs mentions in their gv macro documentation that they can be expanded multiple times. But I'm not sure.

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

No branches or pull requests

1 participant