Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments for anonymous functions #2773

Closed
simonster opened this issue Apr 6, 2013 · 8 comments
Closed

Keyword arguments for anonymous functions #2773

simonster opened this issue Apr 6, 2013 · 8 comments
Assignees
Milestone

Comments

@simonster
Copy link
Member

#485 implemented keyword arguments for named functions. However, I would expect that

(a; b="c") -> a 

would create an anonymous function that takes a keyword argument b with a default value "c". Instead, I currently get

ERROR: syntax: malformed function arguments (block a (= b #<julia_value>))
@ghost ghost assigned JeffBezanson Apr 6, 2013
@StefanKarpinski
Copy link
Member

I'm not entirely sold on this being a necessary feature.

@simonster
Copy link
Member Author

I don't think it's necessary since the same thing can be accomplished with a named function. However, I think there are legitimate reasons to create anonymous functions that take keyword arguments (I ran into this when trying to change PyCall to use keyword arguments instead of the @pykw macro), and the current state of things seems a little inconsistent.

@stevengj
Copy link
Member

stevengj commented Apr 8, 2013

I agree with @simonster consistency is good to have here. Anonymous functions should be first-class in every sense, and that means supporting keywords.

@johnmyleswhite
Copy link
Member

I agree: anonymous functions won't be first-class if they don't share the same abilities as named functions.

@StefanKarpinski
Copy link
Member

Anonymous function are already non-generic, and therefore different. So I'm not sure the they-should-be-the-same argument goes through. I suspect Jeff might have an opinion on the matter ;-)

@JeffBezanson
Copy link
Member

Whether anonymous functions are generic is more of an implementation detail. It might make them different in some respects (e.g. in the future they might be of different types), but the difference shouldn't be so big as to exclude a whole feature like named arguments.

@tonyhffong
Copy link

A question of apply(). For example, if I have

function f(; args... )
    for kv in args
         println( kv )
    end
end

Calling the function by name would give:

julia> f(a=1, b=2)
(:a,1)
(:b,2)

Rather nice. How do I make it work in apply, such as apply( f ; {:a=>1,:b=>2})? (It doesn't work by the way.)

I can visualize functions with lots of named keyword arguments being stored in a dictionary somewhere (like a set of pdf rendering options). It would be useful to just apply this dictionary into a function.

@mbauman
Copy link
Member

mbauman commented Jun 14, 2014

I'm not sure if you can pass keyword args through apply, but you can just splat the dictionary directly into f:

julia> f(;{:a=>1,:b=>2}...)
(:b,2)
(:a,1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants