方法在朱莉娅链接

Tho*_*s E 5 julia

我阅读了https://github.com/JuliaLang/julia/issues/5571,这让我觉得由于一些评论我可以打破这样的界限:

a = [x*5 for x in 0:20 if x>4]

scale(y) = (x)-> y*x
filter(y) = x -> [z for z in x if z>y]

a|>(x->x/3)
    |>scale(2)
    |>filter(4)
    |>println
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

ERROR: LoadError: syntax: "|>" is not a unary operator
 in include_from_node1(::String) at ./loading.jl:488
 in process_options(::Base.JLOptions) at ./client.jl:265
 in _start() at ./client.jl:321
Run Code Online (Sandbox Code Playgroud)

我被迫使用a|>(x->x/3)|>scale(2)|>filter(4)|>println

Dan*_*etz 9

您可以将|>运算符移动到行尾:

julia> a|>(x->x/3)|>
       scale(2)|>
       filter(4)|>
       println
Run Code Online (Sandbox Code Playgroud)

这种语法是因为解析器需要在语句结束时明确地决定.

(实际上,我自己问了一个关于这个问题的问题并得到了一个很好的答案.看看为什么朱莉娅的`where`语法对新行很敏感?)