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

Term rewriting macros being applied repeatly #2901

Closed
reactormonk opened this issue Jun 10, 2015 · 2 comments
Closed

Term rewriting macros being applied repeatly #2901

reactormonk opened this issue Jun 10, 2015 · 2 comments
Labels
Documentation Content Related to documentation content (not generation). RFC

Comments

@reactormonk
Copy link
Contributor

The example listed in http://nim-lang.org/docs/manual.html#term-rewriting-macros-pattern-operators

template t{(0|1|2){x}}(x: expr): expr = x+1
let a = 1
# outputs 2:
echo a

outputs 3, because the template t is applied repeatly. I see both
usecases where you have a repeated application and and where you
don't, how should this be solved?

At least the documentation needs to be fixed.

@reactormonk reactormonk added RFC Documentation Content Related to documentation content (not generation). labels Jun 10, 2015
@kaushalmodi
Copy link
Contributor

I can reproduce this even today. Evaluating the code block in https://nim-lang.org/docs/manual.html#pattern-operators-the-operator gives "3" instead of "2".

@andreaferretti
Copy link
Collaborator

This is somehow implicitly stated in the manual when it mentions

So what about 2 * a? We should tell the compiler * is commutative. We cannot really do that however as the following code only swaps arguments blindly:

The blind swap would get into an infinite loop.

As far as I can tell, this is the intended behaviour (and I think this is right: applying an optimization can trigger more optimizations), so it should just be mentioned in the manual more explicitly

@Araq Araq closed this as completed in 160f859 Oct 11, 2018
narimiran pushed a commit that referenced this issue Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation). RFC
Projects
None yet
Development

No branches or pull requests

3 participants