Map destructuring intended behavior?

120 views
Skip to first unread message

Mike Drogalis

unread,
Jul 17, 2013, 8:46:28 AM7/17/13
to cloju...@googlegroups.com
Problem statement: Map destructuring rules are inconsistent depending on the value of the keywords of the map.


I understand why the error message is what it is, but would it be appropriate for map destructuring to permit the slash inside a symbol for the sake of consistency?

Alex Miller

unread,
Jul 17, 2013, 9:42:37 AM7/17/13
to cloju...@googlegroups.com
That doesn't make sense to me - destructuring creates locally scoped names which are not allowed to be namespaced, so I don't think this is something that should be allowed. 


--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Softaddicts

unread,
Jul 17, 2013, 9:59:39 AM7/17/13
to cloju...@googlegroups.com
+1, strictly local,
Luc
--
Softaddicts<lprefo...@softaddicts.ca> sent by ibisMail from my ipad!

Mike Drogalis

unread,
Jul 17, 2013, 10:00:05 AM7/17/13
to cloju...@googlegroups.com
Makes sense. Thanks guys.

Chouser

unread,
Jul 17, 2013, 11:14:07 AM7/17/13
to cloju...@googlegroups.com
I actually would really like to be able to use :keys to bind
namespaced keywords to local names. This would be exceedingly handy
for example when working with datomic data.

I would want this:
(let [{:keys [a/x]} {:a/x 5}]
x)
;=> 5

That is, you would fully qualify the symbol name in the :keys vector,
but the local bound to it would remain local and unqualified.

There would of course be the potential for keys that could not be
bound this way, for example if the map was {:a/x 5, :b/x 10}. But we
already have this kind of problem for example when using both :strs
and :keys and a map like {:x 5, "x" 10}. In practice this is rarely an
issue, and when it comes up you simply have to use the more verbose
destructuring.

What do you think?
--Chouser

Mike Drogalis

unread,
Jul 17, 2013, 11:20:24 AM7/17/13
to cloju...@googlegroups.com
The Datomic scenario is the reason I posted this. Sorry about failing to mention that.

Thomas Heller

unread,
Jul 17, 2013, 5:45:18 PM7/17/13
to cloju...@googlegroups.com
You can already destructure namespaced keys? Just not via :keys, slightly more code but still nice.

(let [{my-x :a/x :keys [a b] :as m} {:a/x 1 :a 4}] my-x)

Cheers,
/thomas

Alex Miller

unread,
Jul 17, 2013, 6:37:03 PM7/17/13
to cloju...@googlegroups.com
I believe that's the "more verbose destructuring" Chouser referred to.
Reply all
Reply to author
Forward
0 new messages