Re: special case in binding vector syntax for function definitions?

2013-01-25 Thread Ben Wolfson
On Fri, Jan 25, 2013 at 5:38 PM, Alan Malloy  wrote:
> In (let [[x :as y] [1 2]]), there is already an object to make y "point to":
> the vector [1 2]. in ((fn [x :as y]) 1 2), there is no such object.

There's no such object for y to be the tail of in ((fn [x & y] y) 1 2
3), either, but the remaining arguments get accumulated in y
regardless. They even get accumulated in a map in ((fn [& {:as m}] m)
:x 1 :y 2).

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

-- 
-- 
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: special case in binding vector syntax for function definitions?

2013-01-25 Thread Alan Malloy
In (let [[x :as y] [1 2]]), there is already an object to make y "point 
to": the vector [1 2]. in ((fn [x :as y]) 1 2), there is no such object.

On Friday, January 25, 2013 2:18:39 PM UTC-8, Ben wrote:
>
> Both of these work: 
>
> user> (let [[x & y] [1 2]] [x y]) 
> [1 (2)] 
> user> (let [[x :as y] [1 2]] [x y]) 
> [1 [1 2]] 
>
> And this works: 
>
> user> ((fn [x & y] [x y]) 1 2) 
> [1 (2)] 
>
> But this gives an exception (unsupported binding form): 
>
> user> ((fn [x :as y] [x y]) 1 2) 
> ; Evaluation aborted. 
>
> I would have expected this to work and return [1 [1 2]], with y bound 
> to the whole vector implicitly passed to the function (just as it's 
> bound to the tail of the whole vector implicitly passed in the third 
> case). 
>
> This seems to happen because (apparently) the internals of fn* handle 
> rest parameters already, so that clojure.core/maybe-destructured 
> doesn't actually need to do anything to top-level elements of the 
> binding vector: 
>
> clojure.core> (maybe-destructured '[a b] ()) 
> ([a b]) 
> clojure.core> (maybe-destructured '[a & b] ()) 
> ([a & b]) 
> clojure.core> (maybe-destructured '[a [b & c]] ()) 
> ([a p__8059] (clojure.core/let [[b & c] p__8059])) 
>
> Since & is a symbol, it's just passed right through and left to fn* to 
> deal with. But :as is not a symbol, so we end up with this: 
>
> clojure.core> (maybe-destructured '[a :as b] ()) 
> ([a p__8064 b] (clojure.core/let [:as p__8064])) 
>
> Is there a reason for this apparent irregularity? 
>
> -- 
> Ben Wolfson 
> "Human kind has used its intelligence to vary the flavour of drinks, 
> which may be sweet, aromatic, fermented or spirit-based. ... Family 
> and social life also offer numerous other occasions to consume drinks 
> for pleasure." [Larousse, "Drink" entry] 
>

-- 
-- 
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




special case in binding vector syntax for function definitions?

2013-01-25 Thread Ben Wolfson
Both of these work:

user> (let [[x & y] [1 2]] [x y])
[1 (2)]
user> (let [[x :as y] [1 2]] [x y])
[1 [1 2]]

And this works:

user> ((fn [x & y] [x y]) 1 2)
[1 (2)]

But this gives an exception (unsupported binding form):

user> ((fn [x :as y] [x y]) 1 2)
; Evaluation aborted.

I would have expected this to work and return [1 [1 2]], with y bound
to the whole vector implicitly passed to the function (just as it's
bound to the tail of the whole vector implicitly passed in the third
case).

This seems to happen because (apparently) the internals of fn* handle
rest parameters already, so that clojure.core/maybe-destructured
doesn't actually need to do anything to top-level elements of the
binding vector:

clojure.core> (maybe-destructured '[a b] ())
([a b])
clojure.core> (maybe-destructured '[a & b] ())
([a & b])
clojure.core> (maybe-destructured '[a [b & c]] ())
([a p__8059] (clojure.core/let [[b & c] p__8059]))

Since & is a symbol, it's just passed right through and left to fn* to
deal with. But :as is not a symbol, so we end up with this:

clojure.core> (maybe-destructured '[a :as b] ())
([a p__8064 b] (clojure.core/let [:as p__8064]))

Is there a reason for this apparent irregularity?

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

-- 
-- 
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