-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Implement for f.(args...)
syntax
#31553
base: master
Are you sure you want to change the base?
Conversation
@@ -59,7 +62,6 @@ call. Finally, chains of comparisons have their own special expression structure | |||
| `a==b` | `(call == a b)` | | |||
| `1<i<=n` | `(comparison 1 < i <= n)` | | |||
| `a.b` | `(. a (quote b))` | | |||
| `a.(b)` | `(. a b)` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed a.(b)
in "Operators" table (here) and mention it as f.(x)
in "Calls" table since it seems the documentation does not match with the implementation:
> (julia-parse "a.(b)")
(|.| a (tuple b))
Does it support dot operators? e.g. |
Yes julia> x = .- (1:3)
-1:-1:-3
julia> y = x .^ 2
3-element Array{Int64,1}:
1
4
9
julia> collect(for x .+ sqrt.(y))
3-element Array{Float64,1}:
0.0
0.0
0.0 Its parsing and lowering are tested like Lines 1846 to 1847 in 1882eae
and Lines 1865 to 1874 in 1882eae
Let me know if there are other useful test cases. |
So the correct use for iterating would be e.g. The doubling looks weirder than |
I would imagine this pattern is less common than reducers (e.g. |
Fair enough. But Keno's original proposal in #31088 (comment) brought up exactly the point of lowering |
@chethega Yes, that's correct. But this is not a new design. This is a consequence of what was proposed in the triage. |
I feel like it would be better/more explicit a |
I've implemented the macro-based solution in #31088 (I used different macro name but renaming it is quite easy). At this point I think it's up to triage to decide and merge the preferable one. |
I should mention that the |
I think it does not work well if you want to denote |
This PR implements
for f.(args...)
syntax as discussed in #19198 and planned in #31088 (comment).close #19198
close #31088
Implementation detail
Expr(:fordot, :(broadcasted.(expression)))
AST node is introduced to representfor broadcasted.(expression)
.broadcasted
calls by using the pre-existing code injulia-syntax.scm
but skips the outer-mostmaterialize
call.for non(dot(call))
is a syntax error at the moment.for non(dot(call))
is an error at the moment.Demo