Skip to content

Commit

Permalink
add <- as an assignment-like operator
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 4, 2017
1 parent f583495 commit 1820cbb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 1820cbb

Please sign in to comment.