Bit of a confusing title, sorry. Basically I've found myself in positions where I need to invoke a function with named args that I've been passed dynamically:
# like so...
fn_to_call(; some_arg = 123) = println("woooo: $some_arg")
arg_name = :some_arg
arg_val = 678
# I want to invoke my function! The syntax currently supported goes like so:
fn_to_call(; [(arg_name, arg_val)]...)
# Don't get me wrong, that's pretty sweet, but personally I think it could be even more straightforward... like:
fn_to_call(; $arg_name = arg_val)
As I'm writing this I'm starting to think this could cause horrible problems when defining functions inside of macros... but maybe I'm wrong. Either way I'd be interested to hear what people think!
It's a good idea to provide some syntax for this, as it would be pretty easy to support. However I agree that using $ could get confusing.
How about this: any expression after ; that is not of the form x = y gets evaluated, and is treated as a pair whose first element is the keyword and second element is the value. This fits very well with the existing keyword splicing syntax f(x; kw...). For example
x = y
fn(; (arg_name, arg_val))
pair = (arg_name, arg_val)
Cool! That would be pretty sweet
allow fully-evaluated keyword argument pairs. closes #7704
anything in an argument list after a ; that's not of the form `a=b` will
be evaluated and expected to be some kind of pair of a symbol and value.
Wouldn't it be better to use the new Pair syntax for this? i.e. you could call f(...; foo => bar, ...) instead of using (foo,bar).
f(...; foo => bar, ...)
Nevermind, this is automatically allowed because Pair is iterable... seems like it would be cleaner to use the Pair syntax in the documentation, though.
Yes, it's automatically allowed.
I can't believe missed this getting implemented! Thanks so much @JeffBezanson!
documentation for #7704