Open ghost opened 5 years ago
I think this is just a bug. The pattern
:(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: