-
Notifications
You must be signed in to change notification settings - Fork 38
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
& might be a bad choice for de-interpolation #160
Comments
Some information: If we keep the concept of "stage"s in mind (e.g, compile time in CPP is stage 0 and the run time is stage 1), we can explain things cleaner:
Julia already uses
|
So perhaps in our new rewrite, we should consider removing this operator completely? But it would less convenient (basically meaning needs to write another layer of the match in practice) when a pattern need to re-use the first matched variable's value. |
Yes, we need to consider this in our new rewrite. We can learn from Python's design: https://peps.python.org/pep-0636/
However, I'm not sure how to support matching a value that comes from the local scope, or we just do not support this? Actually, this is only supported in pattern matching languages that support pin operators. See this: function func(local_var)
@match value begin
&local_var => ...
end
end |
True, I think we still need a distinguish of local/global scope just because this is not available inside a Julia macro, but if somehow we can get macro caller scope, this would not be necessary the rule is the same as other cases if the name is defined then match the value, instead of assigning a new variable. It seems we have no choice but to have something like this because the support has to be implemented as a macro instead of after-scope gets resolved. It's just we need to think about the operators pred more so perhaps need something else other than |
I think we should just use function Tree.print_node(io::IO, node::SpatialModulationType)
@match node begin
$SpatialModulationType.Global => print(io, "Global")
$SpatialModulationType.ScaledLocations(_) => print(io, "ScaledLocations")
end
end just means we insert a value from outside to the pattern expression, so it will reference to whatever @match ex begin
:($($x) + 1) => true
_ => false
end this means we reference an external value and then insert it into the pattern, if @match ex begin
:($(1) + 1) => true
_ => false
end |
I think you are correct. I'm checking expressions created from Julia parsers could support this. |
Here is a use case for julia> @match :(x + x) :($e + $f) && if e == f end => :(2($e))
:(2x)
julia> @match :(x + x) :($e + $(&e)) => :(2($e))
:(2x) I don't think either of these syntaxes is especially pretty, but the |
it has different pred rule as
$
so it is not very intuitive to use it sometimesthis as a result caused us eval the entire call instead of the object in the following case
&
is still a nice and well-adopted symbol tho, though maybe we just need to find a way to fix the pred by matching more Julia expression patternsThe text was updated successfully, but these errors were encountered: