You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The macro interpreter currently does not create lexical scopes for any block parameters. It is up to each block-accepting macro method to define the block variables when a call is interpreted, and these macro methods all leave the variables untouched after that call finishes:
{%
x =1
[2].each { |x| }
x # => 2%}
This is inconsistent with blocks in normal code which do create a lexical scope. On the other hand, macro for loops destroy the variables upon exit:
{%begin%}
{% x =1%}
{%for x in [2] %}
{%end%}
{% x %} # Error: undefined macro variable 'x'
{%end%}
for loops don't exist in normal Crystal code, but in Ruby they retain the last values of the variables (and it's a great source of confusion there). IMO both macro constructs should support lexical scoping and the local shadowing of variable names.
The text was updated successfully, but these errors were encountered:
The macro interpreter currently does not create lexical scopes for any block parameters. It is up to each block-accepting macro method to define the block variables when a call is interpreted, and these macro methods all leave the variables untouched after that call finishes:
This is inconsistent with blocks in normal code which do create a lexical scope. On the other hand, macro
for
loops destroy the variables upon exit:for
loops don't exist in normal Crystal code, but in Ruby they retain the last values of the variables (and it's a great source of confusion there). IMO both macro constructs should support lexical scoping and the local shadowing of variable names.The text was updated successfully, but these errors were encountered: