Re: Destructuring syntax

2012-01-08 Thread Jeb Beich
Joy of Clojure adds a second reason for this:

The second reason is because it allows us to conjure up other
destructuring features by using forms that would otherwise make no sense.
Because the item on the left of each pair will be a new local name, it must
be a symbol or possibly a nested destructuring form. But one thing it can’t
be is a keyword, unless the keyword is a specially supported feature such
as :keys, :strs, :syms, :as, and :or.

On Wed, Jan 4, 2012 at 7:20 PM, Matthew Boston matthew.bos...@gmail.comwrote:

 I'm with Alex. I think of it as though it's a let binding, cause
 that's basically what's happening; the is bound to the scoped name.

 On Jan 4, 11:29 am, Alex Miller a...@puredanger.com wrote:
  I had the same thought when I first started learning Clojure - I think
  the idea is that there is some nice mental resonance when
  destructuring matches up to your mental model of the data structure
  (it's literal form).  In sequential destructuring, that holds but in
  maps it doesn't so things look backwards.  I think the way I've come
  to understand it is that when doing a let-style binding, the thing
  being bound is always on the left so when destructuring a map, you
  specify the variable, then the key which is looked up to provide the
  value.
 
  On Jan 4, 12:36 am, Johnny Weng Luu johnny.weng@gmail.com wrote:
 
 
 
 
 
 
 
   One thing that seems weird is the way Clojure destructures a map
 
   I have this map: {:last-name Vinge :first-name Vernor} which is
 passed
   to this function: (defn greet-author-2 [{fname :first-name}] ... )
 
   Wouldn't it be better doing: (defn greet-author-2 [{:first-name
 fname}] ...
   )
 
   You first type the keyword, then followed by the parameter to bind to.
 It
   reads that the value is bound to the parameter in the same place.
 
   Feels more natural to me in a way.
 
   Thoughts?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
Jeb Beich
http://www.red-source.net/jeb

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Destructuring syntax

2012-01-04 Thread Johnny Weng Luu
One thing that seems weird is the way Clojure destructures a map

I have this map: {:last-name Vinge :first-name Vernor} which is passed 
to this function: (defn greet-author-2 [{fname :first-name}] ... )

Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ... 
)

You first type the keyword, then followed by the parameter to bind to. It 
reads that the value is bound to the parameter in the same place.

Feels more natural to me in a way.

Thoughts?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Destructuring syntax

2012-01-04 Thread Jay Fields
That does feel a bit more natural, but how would you handle :keys, :as, and :or?

On Wed, Jan 4, 2012 at 1:36 AM, Johnny Weng Luu
johnny.weng@gmail.com wrote:
 One thing that seems weird is the way Clojure destructures a map

 I have this map: {:last-name Vinge :first-name Vernor} which is passed
 to this function: (defn greet-author-2 [{fname :first-name}] ... )

 Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ...
 )

 You first type the keyword, then followed by the parameter to bind to. It
 reads that the value is bound to the parameter in the same place.

 Feels more natural to me in a way.

 Thoughts?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Destructuring syntax

2012-01-04 Thread Ben Smith-Mannschott
On Wed, Jan 4, 2012 at 07:36, Johnny Weng Luu johnny.weng@gmail.com wrote:
 One thing that seems weird is the way Clojure destructures a map

 I have this map: {:last-name Vinge :first-name Vernor} which is passed
 to this function: (defn greet-author-2 [{fname :first-name}] ... )

 Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ...
 )

 You first type the keyword, then followed by the parameter to bind to. It
 reads that the value is bound to the parameter in the same place.

 Feels more natural to me in a way.

 Thoughts?

Doesn't make sense that way around. Remember that in a map, the key is
unique, but the value need not be. Remember that in a Lisp this isn't
just a question of arbitrary syntax. The code you write is always also
a data structure.

With the current solution I can write this, which while not obviously
useful at least has an obvious meaning:

(let [{name1 :name name2 :name} {:name a}]
  (= name1 name2))

Your proposal would seem to allow this:

(let [{:first-name name :last-name name} {:last-name last
:first-name first}]
  (= name ???))

It's not clear what this would mean.

It would also make it impossible to bind the value for a given key to
more than one variable, since map keys must be unique:

(let [{:name name1 :name name2} {:name a}]
  ;; boom? )

// Ben

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Destructuring syntax

2012-01-04 Thread Alex Miller
I had the same thought when I first started learning Clojure - I think
the idea is that there is some nice mental resonance when
destructuring matches up to your mental model of the data structure
(it's literal form).  In sequential destructuring, that holds but in
maps it doesn't so things look backwards.  I think the way I've come
to understand it is that when doing a let-style binding, the thing
being bound is always on the left so when destructuring a map, you
specify the variable, then the key which is looked up to provide the
value.


On Jan 4, 12:36 am, Johnny Weng Luu johnny.weng@gmail.com wrote:
 One thing that seems weird is the way Clojure destructures a map

 I have this map: {:last-name Vinge :first-name Vernor} which is passed
 to this function: (defn greet-author-2 [{fname :first-name}] ... )

 Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ...
 )

 You first type the keyword, then followed by the parameter to bind to. It
 reads that the value is bound to the parameter in the same place.

 Feels more natural to me in a way.

 Thoughts?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Destructuring syntax

2012-01-04 Thread Matthew Boston
I'm with Alex. I think of it as though it's a let binding, cause
that's basically what's happening; the is bound to the scoped name.

On Jan 4, 11:29 am, Alex Miller a...@puredanger.com wrote:
 I had the same thought when I first started learning Clojure - I think
 the idea is that there is some nice mental resonance when
 destructuring matches up to your mental model of the data structure
 (it's literal form).  In sequential destructuring, that holds but in
 maps it doesn't so things look backwards.  I think the way I've come
 to understand it is that when doing a let-style binding, the thing
 being bound is always on the left so when destructuring a map, you
 specify the variable, then the key which is looked up to provide the
 value.

 On Jan 4, 12:36 am, Johnny Weng Luu johnny.weng@gmail.com wrote:







  One thing that seems weird is the way Clojure destructures a map

  I have this map: {:last-name Vinge :first-name Vernor} which is passed
  to this function: (defn greet-author-2 [{fname :first-name}] ... )

  Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ...
  )

  You first type the keyword, then followed by the parameter to bind to. It
  reads that the value is bound to the parameter in the same place.

  Feels more natural to me in a way.

  Thoughts?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en