On Tuesday, April 15, 2014 1:14:16 PM UTC-4, Toivo Henningsson wrote:
>
> Actually, it seems like it already works :) I didn't know that. 
> Also, the 
> <http://docs.julialang.org/en/release-0.2/manual/mathematical-operations/#chaining-comparisons>
> manual<http://docs.julialang.org/en/release-0.2/manual/mathematical-operations/#chaining-comparisons>says
>  that && is used to chain dotless comparisons and & to chain dotted 
> ones. I only wonder what is used if you try a combination such as 1 .< 2 > 
> 0 (which evaluates to true).
>

It doesn't work by translating into .<(a,b,c) for exactly that reason. 
 It's pretty cool:

julia> dump(:(1 .< 2 > 0))
Expr
  head: Symbol comparison
  args: Array(Any,(5,))
    1: Int64 1
    2: Symbol .<
    3: Int64 2
    4: Symbol >
    5: Int64 0
  typ: Any

julia> f() = 1 .< 2 > 0
f (generic function with 1 method)

julia> code_lowered(f,())
1-element Array{Any,1}:
 :($(Expr(:lambda, {}, {{},{},{}}, :(begin  # none, line 1:
        return (1 .< 2) & (2 > 0)
    end))))


It's very impressive, especially if you add another dotless comparator 
(since then it effectively uses &&, with control flow implications).

julia> g() = 1 .< 2 > 0 < 1
g (generic function with 1 method)

julia> code_lowered(g,())
1-element Array{Any,1}:
 :($(Expr(:lambda, {}, {{:#s31},{{:#s31,:Any,2}},{}}, :(begin  # none, line 
1:
        unless 2 > 0 goto 0
        #s31 = 0 < 1
        goto 1
        0:
        #s31 = false
        1:
        return (1 .< 2) & #s31
    end))))

Reply via email to