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

with m1, m2: expands differently from nested with m2: with m1: #21

Open
Technologicat opened this issue Oct 27, 2018 · 0 comments
Open

Comments

@Technologicat
Copy link

These expand differently:

from macropy.core import macros, show_expanded
from unpythonic.syntax import macros, curry

with curry, show_expanded:
    def add3(a, b, c):
        return a + b + c
    assert add3(1)(2)(3) == 6

with show_expanded:
    with curry:
        def add3(a, b, c):
            return a + b + c
        assert add3(1)(2)(3) == 6

I traced this and the issue is triggered by the fact that from the viewpoint of macropy.core.macros.Block.detect_macro, curry doesn't only update the existing nodes in in_tree.body, but replaces the body with something else, when it wraps the original tree in a with dyn.let(...):.

If the macros are invoked in the same with, this new tree is never seen by show_expanded - it gets just the updated nodes of the original in_tree.body.

Using nested with blocks (and keeping in mind the from inside out expansion order), the expansion works as expected - show_expanded sees the with dyn.let(...): inserted by curry.

It seems this can be fixed very simply - PR to follow.

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