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
I like that we support expression literals (as a side effect of comparing values):
julia>@match :(5+5) begin
:(5+5) =>true
_ =>falseendtrue
But while we do accept _ in the struct construction syntax, we don't support them in the expression literal syntax:
julia>@match :(5+5) beginExpr(:call, [:+, _, _])=>true
_ =>falseendtrue
julia>@match :(5+5) begin
:($_ +$_) =>true
_ =>falseend
ERROR: syntax: all-underscore identifier used as rvalue around /Users/nathan.daly/.julia/packages/Rematch/MQlXA/src/Rematch.jl:72
I think the error happens because after #5, we're trying to actually use the value in the _ variable in scope. But I think this should respect our other uses of _ as a rhs variable to mean a wildcard.
Same problem with these:
julia>@match :(5+5) begin
:(a_ + b_) =>true
_ =>falseendfalse
julia>@match :(5+5) begin
:($a_ +$b_) =>true
_ =>falseend
ERROR: UndefVarError: a_ not defined
Stacktrace:
[1] top-level scope at /Users/nathan.daly/.julia/packages/Rematch/MQlXA/src/Rematch.jl:72
It's a bit weird because the $ interpolation means something inside :() and also now means something inside @match. And the names of variables mean something different inside the expression literal than outside it. So i'm not really sure what the right behavior is here...
Fwiw, MacroTool's @match macro gets around this problem because they are always matching expressions by default, not values, so they just always coopt names w/ _ inside expression literals.
There's also this option which currently fails. It would feel wrong to me to make this match because of the potential for an actual _ inside the expression, but I guess this would be most similar to what MacroTools does:
julia>@match :(5+5) begin
:(_ + _) =>true
_ =>falseendfalse
The text was updated successfully, but these errors were encountered:
ghost
changed the title
Should support interpolated _ in expression literal
Should we support interpolated _ in expression literal?
May 7, 2019
:(a + b) should match the expression :(a + b) and nothing else
:($_ + $_) should match any binary addition
:($a + $b) should match any binary addition, and define the pattern variables a and b.
:($$a + $$b) should match an addition, where the left-hand-side corresponds to the value of the local variable a and the right-hand-side corresponds to the value of the local variable b. One $ is for escaping the :, and the other is for escaping the pattern syntax.
I like that we support expression literals (as a side effect of comparing values):
But while we do accept
_
in the struct construction syntax, we don't support them in the expression literal syntax:I think the error happens because after #5, we're trying to actually use the value in the
_
variable in scope. But I think this should respect our other uses of_
as a rhs variable to mean a wildcard.Same problem with these:
It's a bit weird because the
$
interpolation means something inside:()
and also now means something inside@match
. And the names of variables mean something different inside the expression literal than outside it. So i'm not really sure what the right behavior is here...Fwiw, MacroTool's
@match
macro gets around this problem because they are always matching expressions by default, not values, so they just always coopt names w/_
inside expression literals.There's also this option which currently fails. It would feel wrong to me to make this match because of the potential for an actual
_
inside the expression, but I guess this would be most similar to what MacroTools does:The text was updated successfully, but these errors were encountered: