Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

Support arbitrary functional destructuring, that is the use of
any function in any destructuring form to help unpack data in
arbitrary ways.

The discussion began here:
http://clojure-log.n01se.net/date/2009-11-17.html#09:31c

The attached patch implements the spec described here:
http://clojure-log.n01se.net/date/2009-11-17.html#10:50a

That is, the following examples would now work:

user=> (let (link: (-> str a) 1) a)
"1"

user=> (let (link: [a (-> str b) c) (link: 1 2)] (list a b c))
(1 "2" nil)

user=> (let (link: (->> (map int) [a b)) "ab"] (list a b))
(97 98)

8 Answers

0 votes
by

Comment made by: importer

cgrand said: I think the current patch suffers from the problem described here http://groups.google.com/group/clojure-dev/msg/80ba7fad2ff04708 too.

0 votes
by
_Comment made by: importer_

cgrand said: Only -> and ->> are legal here but what if they are aliased or shadowed? Instead of testing the symboil per se I would check, if:
* the symbol is not in &env
* the symbol resolve to #'clojure.core/-> or  #'clojure.core/->>


(when-not (&env (first b)) (#{#'clojure.core/-> #'clojure.core/->>} (resolve (first b))))


but it requires to change destructure's sig to pass the env around
0 votes
by
_Comment made by: importer_

chouser@n01se.net said: Only -> and ->> are actually legal here anyway -- if you've locally bound foo to -> there's not really any good reason to think (fn [(foo inc a)] a) should work.  And if you've redefined -> or ->> to mean something else in your ns, do we need to catch that at compile time, or is it okay to emit the rearranged code and see what happens?

In short, would '#{-> ->> clojure.core/-> clojure.core/->>} be sufficient?
0 votes
by
0 votes
by

Comment made by: importer

chouser@n01se.net said: (link: [file:aHWQ_W06Kr3O89eJe5afGb)]: (link: PATCH) Support -> and ->> in destructuring forms.

0 votes
by

Comment made by: importer

richhickey said: so, don't use syntax-quote, just use clojure.core/->

0 votes
by

Comment made by: stu

Rich: Are you assigned to this by accident? If so, please deassign yourself.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-211 (reported by alex+import)
...