Allowing for keyword arguments in do-block



I wanted to ask if it was considered to add support for keyword arguments in do-block statement?
So that something like:

fun(args; kwargs) do (args2; kwargs2)

would be rewritten as:

end, args; kwargs)

The origin of the proposal is here.


That syntax wouldn’t really be consistent, since

f(args) do (x,y)

gives an anonymous function which takes a single tuple as an argument, i.e. is

f(function ((x,y),)
end, args)

The way to specify a multiple argument function is without parentheses, i.e.

f(args) do x,y

Unfortunately using a semicolon as a keyword separator won’t work, as it is already used as an expression delimiter, i.e.

f(args) do x,y; kw=1

is equivalent to

f(function (x,y)
    kw = 1
end, args)


How about , instead of ;?

f(args) do x, y, kw=1


That’s currently a syntax error (so is available), but would also be inconsistent since the do syntax is used for function definition (in function definitions, a=b args are default values for positional arguments).


How about parsing

map(args) do x, y=1

as the function with default values for positional arguments:

map(function (x, y=1)
end, args)


What would be the point? Presumably map would supply arguments which are congruent, so you would either always get an y, or never do (so just use a constant).

@bkamins: Can you give an example where you would find keyword args useful? I would consider more than 2 (or at most 3, but that’s really pushing it) args for a function I use in a do block code smell.


I asked following the question in

But the example could be (I am not advocating to add it, but just giving an example):

map(round, x, digits=3)

as an equivalent of

round.(x, digits=3)

(the general pattern could be the case when the caller function passes through its keyword arguments to a called function)


Thanks. I understand you are not advocating this, but I think that

would be very confusing, as arguments would end up mapped or not based on being keyword or positional.


Yes - it was only an example of a function we have in Base already.

Note, however, that in broadcasting keyword arguments are exactly not broadcasted over and I guess people expect this behavior.