Destructuring in clojure/binding

2010-02-16 Thread CuppoJava
Hi,
I found this old post:

http://groups.google.com/group/clojure/browse_thread/thread/45e118a638a5af8e/02eab5ae0d9023ff?lnk=gstq=binding+destructuring#02eab5ae0d9023ff

And was wondering what is the status of Stephen's patch?

Is there a reason why clojure/binding does not support destructuring
in its argument list?

(binding [[a b] [1 2]]
  (println a b))

gives:
 java.lang.ClassCastException: clojure.lang.PersistentVector cannot be
cast to clojure.lang.Symbol (NO_SOURCE_FILE:7)


Thanks for the help
  -Patrick

-- 
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: Support for destructuring in clojure/binding

2008-10-09 Thread Krukow



On Sep 22, 4:36 am, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
 I was surprised that clojure/binding doesn't support destructuring bind:

 Clojure
 user= (def a)
 #'user/a
 user= (def b)
 #'user/b
 user= (binding [[a b] [1 2]] (+ a b))

Hello Stephen.

I am not sure I understand. Your example doesn't seem to suggest that
you are really needing a form of destructuring. Rather, it looks like
multiple bindings. Presently, I can do:

krukow:~/languages/clojure/trunk$ cl
Clojure
user= (def a)
#'user/a
user= (def b)
#'user/b
user= (binding [a 1 b 2] (+ a b))
3
user=

Would that be enough?

Kind regards,
- Karl

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Support for destructuring in clojure/binding

2008-10-08 Thread Stephen C. Gilardi

Rich,

This is code from my socket repl that sparked my interest in support  
for destructuring in clojure/binding.

(defn socket-streams ;; returns a vector of 3 streams
   [s]
   [(LineNumberingPushbackReader. (InputStreamReader. (.getInputStream  
s) UTF-8))
(OutputStreamWriter. (.getOutputStream s) UTF-8)
(PrintWriter. (OutputStreamWriter. (.getOutputStream s) UTF-8)   
true)])

(defn socket-repl;; accepts a vector of 3 streams with minimal  
fuss
   Starts a repl thread on the iostreams of supplied socket
   [s]
   (on-thread
#(binding [[*in* *out* *err*] (socket-streams s)] (SocketRepl/ 
repl

I've updated the patch I posted previously. I think this  
implementation is very readable and a nice example of how much  
destructuring, metadata, and reader support for a variety of  
collections can contribute to making Clojure code more clear and  
compact.

http://clojure.googlegroups.com/web/destructuring-binding.patch

Please consider including it in Clojure.

Thanks,

--Steve


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---