Closed bliang26 closed 1 year ago
@bliang26
In apple => "apple"
, the first apple
is treated as a symbol to capture.
According to the Match.jl's documents, now you cannot reference variables to compare with the value to match.
And in MLStyle.jl, use &
:
julia> using MLStyle
julia> @enum Fruit begin
orange
apple
end
julia> fruit = orange
orange::Fruit = 0
julia> @match fruit begin
&apple => "apple"
&orange => "orange"
end
"orange"
What you want is the pin operators from Elixir language.
Just had this problem, caused a bug which lost me hours to track down as I was incorrectly assuming this module would work as it would have in other languages.
As this is my most common use case, I won't be able to continue using this package.
@norru so try MLStyle.jl? :-)
julia> Pkg.status()
Status `~/.julia/environments/v1.6/Project.toml`
[7eb4fadd] Match v2.0.0
julia> @enum Fruit begin
orange
apple
end
julia> fruit = orange
orange::Fruit = 0
julia> @match fruit begin
$apple => "apple"
$orange => "orange"
end
"orange"
Hi, I am getting a wrong result when I try to match an enum. Please see the following example. Is there any work around? Thanks.