if-let* & when-let* with multiple bindings implementation


I think Clojure programs will be more elegant if we use let versions of if & when with multiple bindings.




Alex Miller
August 3, 2017, 8:54 PM

Closing this as a dupe of - please continue work there in that direction.

Alex Miller
July 24, 2017, 3:42 PM

This ticket description starts with a solution. Please instead follow the guidelines for tickets that is written up at https://dev.clojure.org/display/community/Creating+Tickets.

The description should include (in this order):

  • One or two examples demonstrating the cases where existing if-let or when-let are cumbersome

  • A description (NOT code) of the proposed enhancement that will improve this. Describe the semantics of the proposed changes. For example, what happens if only some of the bindings are true? Are previous local bindings available to later local bindings? etc. If there is more than one reasonable answer to these questions, describe the options.

  • State which patch should be considered

Also as an aside, note that if-let and when-let now have specs in core.specs.alpha - if you modify these, you must also include a patch that updates the specs. If you add new macros, you should include a patch that adds the corresponding specs. As the specs are on a different repo, the spec change changes should be in a separate patch.

Justin Spedding
July 23, 2017, 6:38 PM

After giving it some more thought, I do not see much of a reason to have separate macros for if-let and if-let*. Why not just extend the base if-let, if-some, when-let, and when-some to accept multiple bindings?

These macros produce the same output if used with just one binding, but are also capable of handling multiple bindings:

Justin Spedding
July 22, 2017, 9:47 PM

I wrote an alternate version of if-let* and if-some* that do not leak bindings into the else clause:

Michael Blume
July 6, 2017, 8:36 PM

My example under your implementation expands to

and evaluates to :shadowed