Skip to content
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

RFC: add <- as an assignment-like operator #19765

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Julia v0.6.0 Release Notes
New language features
---------------------

* `<-` is now a valid operator that can be defined for custom purposes.
It has assignment precedence. ([#19765])

Language changes
----------------

Expand Down
6 changes: 4 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
;; be an operator.
(define prec-assignment
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻=))
'(:= => ~ $=)))
'(:= => ~ $= <-)))
(define prec-conditional '(?))
(define prec-arrow (append!
'(-- -->)
Expand Down Expand Up @@ -729,7 +729,9 @@
(let ((args (parse-chain s down '~)))
`(macrocall @~ ,ex ,@(butlast args)
,(loop (last args) (peek-token s)))))
(list t ex (parse-assignment s down)))))))
(if (syntactic-op? t)
(list t ex (parse-assignment s down))
(list 'call t ex (parse-assignment s down))))))))

(define (parse-eq s)
(let ((lno (input-port-line (ts:port s))))
Expand Down
6 changes: 6 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ end
@test parse("x<:y<:z").head === :comparison
@test parse("x>:y<:z").head === :comparison

# PR #19765
let <-(x,y) = 2x + y
@test (3<-10) == 16
end
@test parse("x<-y<-z") == Expr(:call, :(<-), :x, Expr(:call, :(<-), :y, :z))

# issue #11169
uncalled(x) = @test false
fret() = uncalled(return true)
Expand Down