Julia: pmap argument order does not allow for do-block syntax

Created on 2 Apr 2018  路  2Comments  路  Source: JuliaLang/julia

Every remotecall method currently has the function argument first so that do-block syntax can be used (#13338).

julia> methods(remotecall)
# 4 methods for generic function "remotecall":
remotecall(f, w::Base.Distributed.LocalProcess, args...; kwargs...) in Base.Distributed at distributed/remotecall.jl:318
remotecall(f, w::Base.Distributed.Worker, args...; kwargs...) in Base.Distributed at distributed/remotecall.jl:324
remotecall(f, id::Integer, args...; kwargs...) in Base.Distributed at distributed/remotecall.jl:336
remotecall(f, pool::Base.Distributed.AbstractWorkerPool, args...; kwargs...) in Base.Distributed at distributed/workerpool.jl:160

This is not the case for pmap, where the first argument is sometimes an AbstractWorkerPool. It would be great to make these consistent with each other and allow do-block syntax for pmap.

julia> methods(pmap)
# 4 methods for generic function "pmap":
pmap(p::Base.Distributed.AbstractWorkerPool, f, c; distributed, batch_size, on_error, retry_delays, retry_check) in Base.Distributed at distributed/pmap.jl:101
pmap(p::Base.Distributed.AbstractWorkerPool, f, c1, c...; kwargs...) in Base.Distributed at distributed/pmap.jl:155
pmap(f, c; kwargs...) in Base.Distributed at distributed/pmap.jl:156
pmap(f, c1, c...; kwargs...) in Base.Distributed at distributed/pmap.jl:157
parallel

Most helpful comment

Why not have syntax for passing the do function to any argument.

e.g. passing -> to any parameter means "pass the do function to this parameter".
So, the following would all be equivalent:

mapreduce(x->x, (a,b)->a+b, [1,2,3])

mapreduce((a,b)->a+b, [1,2,3]) do x
    x
end

mapreduce(->, (a,b)->a+b, [1,2,3]) do x
    x
end

mapreduce(x->x, ->, [1,2,3]) do a, b
    a + b
end

All 2 comments

cc @amitmurthy

Why not have syntax for passing the do function to any argument.

e.g. passing -> to any parameter means "pass the do function to this parameter".
So, the following would all be equivalent:

mapreduce(x->x, (a,b)->a+b, [1,2,3])

mapreduce((a,b)->a+b, [1,2,3]) do x
    x
end

mapreduce(->, (a,b)->a+b, [1,2,3]) do x
    x
end

mapreduce(x->x, ->, [1,2,3]) do a, b
    a + b
end
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sbromberger picture sbromberger  路  3Comments

yurivish picture yurivish  路  3Comments

manor picture manor  路  3Comments

tkoolen picture tkoolen  路  3Comments

omus picture omus  路  3Comments