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

fnk binding form can't combine optional parameters with destructuring #114

Open
vilmibm opened this issue Jan 11, 2016 · 4 comments
Open

Comments

@vilmibm
Copy link

vilmibm commented Jan 11, 2016

When defining a fnk, I'd hope to be able to do something like this:

((fnk [{[:sub foo] 1} bar] (+ foo bar)) {:sub {:bar 1}})

to get back 2. Unfortunately, combining the optional {} syntax with the [] destructuring syntax does not work:

CompilerException java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Named, compiling:(*cider-repl trapperkeeper*:16:32) 
@w01fe
Copy link
Member

w01fe commented Jan 11, 2016

Thanks for the report. This is currently by design -- I don't see an easy way to provide a default in the case that the sub-form binds more than one symbol, and the semantics of what's required vs. optional isn't exactly clear (does this mean that :sub is optional, but if present must contain a foo?).

Given the complexities, we've felt that in such cases, we're probably better just using what Clojure provides already. But if you have a concrete proposal for how you'd like this to work that covers all the cases, we'd be happy to consider it.

@vilmibm
Copy link
Author

vilmibm commented Jan 14, 2016

@w01fe Thanks for the speedy reply. I wondered if this was the case.

I'd be happy to write up a proposal / work on implementing it if y'all approved.

I'm getting over a headcold (hence my delayed response) but I'll try to get to that proposal soon.

@w01fe
Copy link
Member

w01fe commented Jan 14, 2016

Sounds good, thanks for the offer! If you can prepare something along the lines of the "fnk syntax proposal" here: https://github.com/plumatic/plumbing/tree/master/src/plumbing/fnk that covers all the cases that would be ideal, and we can review and take things from there. Cheers!

@vilmibm
Copy link
Author

vilmibm commented Jan 14, 2016

👍

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

2 participants