-
Notifications
You must be signed in to change notification settings - Fork 5
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
Optional matching #42
Comments
It's a slurp, so it can only match a variable number of elements in a single syntax type e.g. What you want is some sort of "optional" special syntax, which there isn't one yet. Right now you need to use two methods: @metafunction fte(function f(*{args}); *{stmts} end) =
fte(:(function f($(args...))::Any; $(stmts...) end))
@metafunction fte(function f(*{args})::T; *{stmts} end) begin
println(f)
println(args)
println(T)
println(stmts)
end It shouldn't be too difficult making a @metafunction fte(function f(*{args})::(:opt{T, Any}); *{stmts} end)
...
end I can work on that if you think that's a desirable feature. |
Thanks, that is what i have done too, Thanks |
Thanks for the interest! If you need any help feel free to submit a WIP and/or ask any questions. |
Hi, I am implementing the :O or :optional special for the following syntax matching: @metafunction fte(function f(*{args})(:O{:L{::}:A{rt}}); *{stmts} end)
...
end So I am thinking to implement this as a special PatternGate, then I should check whether there is a match if not roll back and continue with the other child of the parent node. Thanks |
Remember that julia expressions are tree-like, so that pattern can't work.
Not
Or some other vector-like shape. I recommend using My idea for an implementation would look like this: f(*{args})::(:O{rt})
f(*{args})::(:O{rt, Any}) Otherwise behaving about the same way as you described (If I understood correctly), but working from the parent node instead of the
|
I think following symbol of | as an OR is much more better to match, In the following pattern, the second argument is optional: function (name(*{args}) | :O{::rt}) *{stats} end it tries to match name({args}) or name({args})::rt In the following pattern, the second argument is not optional, this means straight forward OR function (name(*{args}) | name(*{args})::rt) *{stats} end |
If you use normal julia syntax like I thought about the I don't understand your first example. Does (also, |
Hi @Qiyamah, do you still want to do this? Just checking because I might refactor a lot of code soon and might end up taking a look at this in the process if you can't or don't want to work on it. You've already done a lot for the project just by showing interest, I would have probably just given up on this if not for that (your ideas and bug reports were very much appreciated too!), so don't worry about dropping this if you've lost interest/got busy/etc, you've been a great help already. |
Hi,
is supposed to match something like :
:(function f(x,y) x+y end)
or:(function f(x,y)::Int x+y end)
but it is unable to match against
:(function f(x,y) x+y end)
?
means reluctant match right? Doesn't this means it may match nothing?Thanks
The text was updated successfully, but these errors were encountered: