Clojure

let-> needs improvement

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

The function clojure.core/let-> is suboptimal in a few regards:
1. It's name lends you to believe it is "let-like", but it is not - it does not take a binding form, and its arguments are 'backwards'
2. It's docstring doesn't make clear that it is intended for use solely in a threading-macro expression
3. It arbitrarily does not support destructuring, where it easily could.

Possible solutions:

  • rename it (e.g. to "bind->") to make clear it is not let-like
  • allow destructuring of the 'name' parameter

Google groups discussion: https://groups.google.com/d/topic/clojure/67JQ7xSUOM4/discussion

Activity

Rich Hickey made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Approval Not Approved [ 10008 ]
Status Open [ 1 ] Closed [ 6 ]
Hide
Yongqian Li added a comment -

Has it been decided whether as-> supports de-structuring or not? Right now it is inconsistent.

(as-> [0 1]
      [a b]
  [(inc a) (inc b)])

 => [1 2]



(as-> {:a 0 :b 1}
      {:keys [a b]}
  {:a (inc a) :b (inc b)})

 => {:keys [1 2]}
Show
Yongqian Li added a comment - Has it been decided whether as-> supports de-structuring or not? Right now it is inconsistent.
(as-> [0 1]
      [a b]
  [(inc a) (inc b)])

 => [1 2]



(as-> {:a 0 :b 1}
      {:keys [a b]}
  {:a (inc a) :b (inc b)})

 => {:keys [1 2]}
Hide
Yongqian Li added a comment -

Also, what about changing the name to >as? ->as reads like "pipeline as name", whereas as> implies that you are starting a new pipeline.

(-> 0
  (->as name 
    (...))

Makes it clearer that you are consuming a pipeline and the expressions within ->as are no longer being influenced by ->.

Show
Yongqian Li added a comment - Also, what about changing the name to >as? ->as reads like "pipeline as name", whereas as> implies that you are starting a new pipeline.
(-> 0
  (->as name 
    (...))
Makes it clearer that you are consuming a pipeline and the expressions within ->as are no longer being influenced by ->.
Hide
Yongqian Li added a comment -

Has the addition of ->>as been considered? That way you can use it inside a ->> like this:

(->> a 
  (->>as name
    (...)))

(-> a 
  (->as name
    (...)))

The signature would be [name forms init-expr].

Show
Yongqian Li added a comment - Has the addition of ->>as been considered? That way you can use it inside a ->> like this:
(->> a 
  (->>as name
    (...)))

(-> a 
  (->as name
    (...)))
The signature would be [name forms init-expr].

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: