JuliaLang/julia

ternary operator with "return" gives a parse error

Open

#9,180 建立於 2014年11月27日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Julia (5,773 fork)batch import
help wantedparser

倉庫指標

Star
 (48,709 star)
PR 合併指標
 (平均合併 20天 6小時) (30 天內合併 157 個 PR)

描述

As discussed here: https://groups.google.com/forum/?fromgroups=#!topic/julia-users/9Ps2xYWSWMQ julia parses ternary operator with return not correct (or at least not intuitive).

function bar(x)
    x > 10 ? return(0) : nothing
    2
end

and

function bar(x)
    x > 10 ? return 0 : nothing
    2
end

result in "ERROR: syntax: colon expected in "?" expression".

The versions below work as expected.

function foo(x)
    x <= 10 ? nothing : return(0)
    2
end

or that

function foo(x)
    x > 10 ? (return 0) : nothing
    2
end

貢獻者指南