plumatic / plumbing

Prismatic's Clojure(Script) utility belt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fnk binding form can't combine optional parameters with destructuring

vilmibm opened this issue · comments

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) 

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.

@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.

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!

👍