Re: Discuss: Add a :let special expression to cond

2009-10-18 Thread Howard Lewis Ship
, a test of :let injects an implicit let (the expression should be a vector of binding forms). The new bindings may be referenced in later tests and expressions. (cond) returns nil. [ clauses] (when clauses ; Jumping through many hoops, as cond is fundamental to many ; other basic forms

Re: let-while

2009-10-17 Thread mbrodersen
I think I understand what you are trying to do John but it doesn't have the same semantics though. If you use the first definition, the following expression: (let-while [x (if ( (rand) 0.2) Yep! nil)] (println x) (println (str x will work correctly (it will print Yep! and Yep!Yep! zero

Re: let-while

2009-10-17 Thread Jarkko Oranen
with the binding name... both versions of the macro seem to expand to identical code: user= (macroexpand-1 '(while-let [a nil] (foo))) (clojure.core/loop [] (clojure.core/let [a nil] (clojure.core/when a (foo) (recur So my naive view was they would have identical behaviour/performance

Re: let-while

2009-10-17 Thread mbrodersen
I don't think the multiple evaluation matters in this case, since it's the name parameter, which will in all sane cases be a simple symbol. gensyms are needed when multiple evaluation could cause side-effects or an expensive function to be computed multiple times, which is not the case here.

Discuss: Add a :let special expression to cond

2009-10-17 Thread Howard Lewis Ship
I keep coming into situations where I'd like a let in the middle of my cond. I often do a couple of tests, then would like to lock down some symbols that I'll use frequently in the remaining cases. There's a precedent for this, in that the for macro allows a :let as an alternative to a list

Re: Discuss: Add a :let special expression to cond

2009-10-17 Thread Sean Devlin
So you have a working version of this macro, as well as some use cases in actual code? This would help the discussion a lot. Thanks! On Oct 17, 10:43 am, Howard Lewis Ship hls...@gmail.com wrote: I keep coming into situations where I'd like a let in the middle of my cond.  I often do

Re: let-while

2009-10-17 Thread John Harrop
appreciate the issue with the binding name... both versions of the macro seem to expand to identical code: user= (macroexpand-1 '(while-let [a nil] (foo))) (clojure.core/loop [] (clojure.core/let [a nil] (clojure.core/when a (foo) (recur So my naive view was they would have identical behaviour

Re: let-while

2009-10-17 Thread Christophe Grand
Hi all, On Sat, Oct 17, 2009 at 2:12 AM, John Harrop jharrop...@gmail.com wrote: On Fri, Oct 16, 2009 at 7:58 PM, mbrodersen morten.broder...@gmail.comwrote: Hi, I am new to Clojure and I am wondering if there is anything similar to the following macro already built in: (defmacro let

Re: Discuss: Add a :let special expression to cond

2009-10-17 Thread Howard Lewis Ship
: I keep coming into situations where I'd like a let in the middle of my cond.  I often do a couple of tests, then would like to lock down some symbols that I'll use frequently in the remaining cases. There's a precedent for this, in that the for macro allows a :let as an alternative to a list

Re: Discuss: Add a :let special expression to cond

2009-10-17 Thread Howard Lewis Ship
...@gmail.com wrote: I keep coming into situations where I'd like a let in the middle of my cond.  I often do a couple of tests, then would like to lock down some symbols that I'll use frequently in the remaining cases. There's a precedent for this, in that the for macro allows a :let as an alternative

Re: let-while

2009-10-17 Thread mbrodersen
That's a nice improvement Christophe. Exactly the kind of answer I was looking for. Thanks! Morten --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: let-while

2009-10-17 Thread Timothy Pratley
On Oct 18, 5:27 am, Christophe Grand christo...@cgrand.net wrote: (defmacro while-let  Makes it easy to continue processing an expression as long as it is true  [binding forms]   `(loop []      (when-let ~binding       �...@forms        (recur Nice! Would you be willing to add

Re: let-while

2009-10-17 Thread John Harrop
On Sat, Oct 17, 2009 at 2:27 PM, Christophe Grand christo...@cgrand.netwrote: (defmacro while-let Makes it easy to continue processing an expression as long as it is true [binding forms] `(loop [] (when-let ~binding ~...@forms (recur This does look like

Re: let-while

2009-10-17 Thread mbrodersen
It would be great to have while-let in contrib. Then I don't have to maintain let-while myself :-) Morten --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure

let-while

2009-10-16 Thread mbrodersen
Hi, I am new to Clojure and I am wondering if there is anything similar to the following macro already built in: (defmacro let-while Makes it easy to continue processing an expression as long as it is true [[name expr] forms] `(loop [] (let [~name ~expr

Re: let-while

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 7:58 PM, mbrodersen morten.broder...@gmail.comwrote: Hi, I am new to Clojure and I am wondering if there is anything similar to the following macro already built in: (defmacro let-while Makes it easy to continue processing an expression as long

Re: let-while

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 8:12 PM, John Harrop jharrop...@gmail.com wrote: (defmacro let-while Makes it easy to continue processing an expression as long as it is true [[name expr] forms] (let [n# ~name] `(loop [] (let [~n# ~expr] (when ~n# ~...@forms

Bug? Primitives get boxed if passed out of let.

2009-07-30 Thread Rich Hickey
On Thu, Jul 30, 2009 at 1:28 AM, John Harropjharrop...@gmail.com wrote: user= (loop [i 0 j (double 1.0)]   (if (= i 1) j (recur 1 (+ j j 2.0 user= (loop [i 0 j (double 1.0)]   (if (= i 1) j (recur 1 (let [a j b j] (+ a b) #CompilerException java.lang.RuntimeException

Re: let a variable number of bindings

2009-07-18 Thread John Harrop
On Fri, Jul 17, 2009 at 11:52 PM, Rowdy Rednose rowdy.redn...@gmx.netwrote: How can I lexically bind names like let does in a macro, when names and values for those bindings are passed in? This here works fine when I pass a literal collection: (defmacro let-coll [coll body] `(let

Re: let a variable number of bindings

2009-07-18 Thread John Harrop
On Sat, Jul 18, 2009 at 1:22 AM, Meikel Brandmeyer m...@kotka.de wrote: Using eval is not really a solution. (def foo '[a 1 b 2]) (let-coll foo ...) will probably work with eval, but (let [foo '[a 1 b 2]] (let-coll foo ...)) will not. No, for that you need to make the macro run-time

Re: let a variable number of bindings

2009-07-18 Thread Rowdy Rednose
(defmacro let-coll [ks val-fn body] `(let ~(vec (mapcat #(list % `(~val-fn '~%)) ks)) ~...@body)) allows me to do this: user= (def m {'a 1 'b 2 'c 3}) #'user/m user= (let-coll (a b c) m (list a b c)) (1 2 3) And although the macro itself looks a bit ugly (suggestions on improvement

Re: let a variable number of bindings

2009-07-18 Thread Meikel Brandmeyer
need to retrieve at run time. Good to hear, you found a solution for your problem. (defmacro let-coll [ks val-fn body] `(let ~(vec (mapcat #(list % `(~val-fn '~%)) ks)) ~...@body)) Another idea might be to translate the symbols for the variables to keywords in the map. That would save you

Re: let a variable number of bindings

2009-07-18 Thread Jarkko Oranen
user= (macroexpand-1 '(let-coll [a b c] {:a 1 :b 2 :c 3} (println a b   c))) (clojure.core/let [val-fn__23 {:a 1, :b 2, :c 3}                     a          (val-fn__23 :a)                     b          (val-fn__23 :b)                     c          (val-fn__23 :c)]    (println a b c

Re: let a variable number of bindings

2009-07-18 Thread Meikel Brandmeyer
Hi Jarkko, Am 18.07.2009 um 22:02 schrieb Jarkko Oranen: That looks a lot like map destructuring, though: (let [{:keys [a b c]} {:a 1 :b 2 :c 3}] (list a b c)) - (1 2 3) Yes. But val-fn might also be exactly that: a function which gets the value by some others means than a map. I'm

Re: let a variable number of bindings

2009-07-18 Thread Rowdy Rednose
that via macros (as I just proved :). My macro's destructuring features are of course much more limited than Clojure's. On Jul 19, 5:07 am, Meikel Brandmeyer m...@kotka.de wrote: Hi Jarkko, Am 18.07.2009 um 22:02 schrieb Jarkko Oranen: That looks a lot like map destructuring, though: (let [{:keys

let a variable number of bindings

2009-07-17 Thread Rowdy Rednose
How can I lexically bind names like let does in a macro, when names and values for those bindings are passed in? This here works fine when I pass a literal collection: (defmacro let-coll [coll body] `(let ~(vec coll) ~...@body)) user= (let-coll [a 11 b 22] (list b a)) (22 11) Doing

Re: let a variable number of bindings

2009-07-17 Thread Meikel Brandmeyer
Hi, Am 18.07.2009 um 05:52 schrieb Rowdy Rednose: How can I lexically bind names like let does in a macro, when names and values for those bindings are passed in? You can't. A macro cannot depend on runtime information (for some suitable definition of runtime information, I know). In a call

Re: Bug report -- macros within let [Re: Bizarre behavior (bug?) for unchecked-add]

2009-06-09 Thread Laurent PETIT
, -- Laurent 2009/4/24 Christophe Grand christo...@cgrand.net: Hi Kevin! Your (let [dummy 0] ...) is a single expression and, as such, is entirely compiled before being executed. But to properly compile (add 1 (mul magic x)) 'add need to have a value and it will not have a value until the (compiled

In let: unpacking maps with accessors too

2009-06-08 Thread samppi
I'd love to be able to do this: (defstruct person-s :name :gender) (def name-a (accessor person-s :name)) (def gender-a (accessor person-s :gender)) (def person-1 (struct person-s Jane :female)) (let [{name name-a, gender gender-a, :as person} person-1] (println name gender person

Re: In let: unpacking maps with accessors too

2009-06-08 Thread Konrad Hinsen
On Jun 8, 2009, at 17:46, samppi wrote: ...I'd love it if the values of symbol keys could be any symbol, not just keywords, so that the key symbol is bound to (val-symbol the-map): (let [{name this-is-a-symbol} person-1] ...) ; name is bound to (this-is-a-symbol person-1) It's backwards

Re: In let: unpacking maps with accessors too

2009-06-08 Thread joshua-choi
Oh, I didn't know that. It makes me wonder, then, why integers were not implemented as functions of sequential collections: (3 [:a :b :c]). Ah, well. I guess since let can't be changed, it's then a choice between using accessors or being more elegant. Thanks for the reply. On Jun 8, 9:25 am

Bug report -- macros within let [Re: Bizarre behavior (bug?) for unchecked-add]

2009-04-24 Thread ke...@ksvanhorn.com
I have more information on this now, and it is definitely a bug in Clojure -- defmacro within a let doesn't work correctly. Consider the following file: --- BEGIN foo1a.coj --- (ns com.ksvanhorn.foo1a) (let [dummy 0] (defmacro add [ args] `(unchecked-add ~...@args)) (defmacro mul [ args

Macros, let and variable capture

2009-04-09 Thread Paul Drummond
that generates the code I want but I get Can't let qualified name errors. This is where my understanding of macros is giving me problems. I want the forms inside vlayout to expand to local vars in a let form. The above example would expand to: (let [b (create-button) l (create-label

Re: Macros, let and variable capture

2009-04-09 Thread Christophe Grand
Hi Paul Paul Drummond a écrit : (defmacro defwidget [ body] `(let [panel# (javax.swing.JPanel.) ~@(flat1 (map (fn [[type inst]] [inst (list type)]) (rest (first body] ~(second body) (doto panel# (.setLayout (javax.swing.BoxLayout. panel# javax.swing.BoxLayout

Re: Macros, let and variable capture

2009-04-09 Thread Paul Drummond
2009/4/9 Christophe Grand christo...@cgrand.net: The problem is with the last two lines of your macro (the let expansion is fine):      (.add l)      (.add b Do you really want to hardcode l and b here or emit as many .add as required? No - this is where the macro is incomplete

Re: let vs. let*

2009-03-07 Thread Meikel Brandmeyer
Hi, Am 07.03.2009 um 07:11 schrieb Stephen C. Gilardi: let* is an an internal implementation detail that supports the special form let. let* does no destructuring. And one might add, that let* is not part of the public API and should not be used directly. Sincerely Meikel smime.p7s

let vs. let*

2009-03-06 Thread David Sletten
I see a lot of let* in macro expansions, but Clojure's let already behaves like Common Lisp's LET*. Is let* archaic? It seems to behave the same as let in terms of sequential binding. (let [x 8 y (inc x)] (list x y)) = (8 9) (let* [x 8 y (inc x)] (list x y)) = (8 9) Aloha, David Sletten

Re: let vs. let*

2009-03-06 Thread Stephen C. Gilardi
let* is an an internal implementation detail that supports the special form let. let* does no destructuring. --Steve On Mar 7, 2009, at 12:49 AM, David Sletten da...@bosatsu.net wrote: I see a lot of let* in macro expansions, but Clojure's let already behaves like Common Lisp's LET

Re: Opinions on - macro? (was Re: Extensive use of let?)

2009-03-01 Thread Meikel Brandmeyer
Hi, Am 01.03.2009 um 02:19 schrieb Belfabius: I quickly learned the - macro can't be used in the same way for one simple reason; the value that is threaded through to the forms is always placed in the first argument position. How about adding a macro -- it could be called | just as in F# --

Re: Opinions on - macro? (was Re: Extensive use of let?)

2009-02-28 Thread Stuart Sierra
On Feb 27, 1:39 pm, John D. Hume duelin.mark...@gmail.com wrote: As a Java/Ruby guy who is not used to reading inside out, I'm curious as to whether people who ARE accustomed to LISP find the - macro distracting since it flops things around. Are there circumstances where you prefer it?

Re: Opinions on - macro? (was Re: Extensive use of let?)

2009-02-28 Thread Belfabius
First, I have to say thanks. I'm only a part-time Clojure user, and I didn't know of the - macro until today. Second, I think the - syntax leads to more readable code for precisely those situations where you're coding a sequence of actions. Finally, I've got a comment about what I think might

Opinions on - macro? (was Re: Extensive use of let?)

2009-02-27 Thread John D. Hume
On Wed, Feb 25, 2009 at 4:11 PM, Jason Wolfe jawo...@berkeley.edu wrote: (you'll get use to reading inside-out quickly). As a Java/Ruby guy who is not used to reading inside out, I'm curious as to whether people who ARE accustomed to LISP find the - macro distracting since it flops things

Re: Opinions on - macro? (was Re: Extensive use of let?)

2009-02-27 Thread James Reeves
On Feb 27, 6:39 pm, John D. Hume duelin.mark...@gmail.com wrote: As a Java/Ruby guy who is not used to reading inside out, I'm curious as to whether people who ARE accustomed to LISP find the - macro distracting since it flops things around. Are there circumstances where you prefer it? It's

Re: Opinions on - macro? (was Re: Extensive use of let?)

2009-02-27 Thread Allen Rohner
It's pretty useful for nested keywords:   (:name (:profile (:user message)))   (- message :user :profile :name) - James That is really cool. Once again the language and the community impress me with how elegant the language is. Allen

Re: Extensive use of let?

2009-02-26 Thread Luke VanderHart
/297e266b0badf0f301a556e957... On Wed, Feb 25, 2009 at 12:57 PM, levand luke.vanderh...@gmail.com wrote: Recently, in my code, I have been struggling with which of the two equivalent forms is, in a general sense, better. (defn my-fn1 [input]  (let [value1 (op1 input)        value2 (op2 input

Extensive use of let?

2009-02-25 Thread levand
Recently, in my code, I have been struggling with which of the two equivalent forms is, in a general sense, better. (defn my-fn1 [input] (let [value1 (op1 input) value2 (op2 input) value3 (op4 value1 value2)] (op5 value3))) (defn my-fn2 [input] (op5 (op4 (op1 input) (op2

Re: Extensive use of let?

2009-02-25 Thread Joshua Fox
Of course, the use of let does not make the code any more imperative or less functional, as long as there are no side effects. Also, the scope is limited to the let block, keeping it clean, and there should be no harm to performance. IMHO, the code with let is simply more readable and therefore

Re: Extensive use of let?

2009-02-25 Thread Jason Wolfe
There's also a middle ground: (defn my-fn2 [input]   (op5 (op4 (op1 input) (op2 input If your op names are descriptive, this can still be very easy to read, with significantly fewer characters than the let version (you'll get use to reading inside-out quickly). You can also

Re: Extensive use of let?

2009-02-25 Thread Laurent PETIT
a more abstract name given in the let could help the rest of the let body be itself more abstract too ? * it is possible to abuse both forms if you replace a careful thought of the pros and cons with a global rule which, while certainly written with the best intent in mind, endlessly becomes

Re: Extensive use of let?

2009-02-25 Thread Kevin Downey
/hiredman/clojurebot/tweet.clj#L11 On Wed, Feb 25, 2009 at 12:57 PM, levand luke.vanderh...@gmail.com wrote: Recently, in my code, I have been struggling with which of the two equivalent forms is, in a general sense, better. (defn my-fn1 [input]  (let [value1 (op1 input)        value2 (op2 input

with-local-vars vs. let

2009-02-13 Thread Mark Volkmann
What are some reasons to use with-local-vars instead of let or binding? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email

Re: with-local-vars vs. let

2009-02-13 Thread Konrad Hinsen
On Feb 13, 2009, at 13:31, Mark Volkmann wrote: What are some reasons to use with-local-vars instead of let or binding? Let just creates bindings for a lexical scope. They cannot be modified at all. Binding and with-local-vars deal with vars, i.e. mutable references. Binding creates

Re: with-local-vars vs. let

2009-02-13 Thread Adrian Cuthbertson
instead of let or binding? Let just creates bindings for a lexical scope. They cannot be modified at all. Binding and with-local-vars deal with vars, i.e. mutable references. Binding creates a dynamic scope for already existing vars that are accessible in some namespace. With-local-vars also

Re: with-local-vars vs. let

2009-02-13 Thread Konrad Hinsen
On Feb 13, 2009, at 15:35, Adrian Cuthbertson wrote: Have a look at compojure - a good example of with-local-vars is where a servlet request is executed. Each (get, post) request occurs in its entirety on a single (jetty or tomcat) thread. The compojure call to the application service

Re: with-local-vars vs. let

2009-02-13 Thread Adrian Cuthbertson
What I see in your example is binding, but I don't see with-local- vars anywhere. Or did I misunderstand something? Sorry, I checked the compojure source again and the servlet headers, cookies, etc are wrapped in a with-servlet-vars macro (rather than with-local-vars) which just uses let

let and binding have different ordering behavior

2009-02-12 Thread Stuart Sierra
Whoops, this caught me today. Whereas let evaluates its bindings sequentially, binding does not! Observe: (def a a1) (def b b1) (let [a a2, b a] b) ;;= a2 (binding [a a2, b a] b) ;;= a1 I wouldn't call this a bug, but I think it's worth noting in the doc string for binding. -Stuart Sierra

Re: let and binding have different ordering behavior

2009-02-12 Thread Mark Volkmann
On Thu, Feb 12, 2009 at 3:26 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: Whoops, this caught me today. Whereas let evaluates its bindings sequentially, binding does not! Observe: (def a a1) (def b b1) (let [a a2, b a] b) ;;= a2 (binding [a a2, b a] b) ;;= a1 I wouldn't

Re: let and binding have different ordering behavior

2009-02-12 Thread Phil Hagelberg
Mark Volkmann r.mark.volkm...@gmail.com writes: Whoops, this caught me today. Whereas let evaluates its bindings sequentially, binding does not! Observe: (def a a1) (def b b1) (let [a a2, b a] b) ;;= a2 (binding [a a2, b a] b) ;;= a1 I wouldn't call this a bug, but I think it's

Re: if-let

2009-02-09 Thread jdz
(let [basedir (if-let [bdir (:basedir *locs)] bdir .)]     ...) I'd personally write that as: (let [basedir (or (:basedir *locs*) .)] ...) There is also when-let, which can be used to iterate over sequences: (loop [items some-sequence] (when-let [item (first items)] (do something

if-let

2009-02-08 Thread Mark Volkmann
Can someone show me an example of a good use of if-let? I find its doc string a little confusing. It says If test is true, evaluates then with binding-form bound to the value of test, if not, yields else. However, it doesn't have a parameter named test. I assume it means If the binding evaluates

Re: if-let

2009-02-08 Thread Meikel Brandmeyer
Hi, Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson: Here's one, I'm setting basedir to either :basedir in a map in *locs (a thread-local var) or to . if :basedir was not found in the map... (let [basedir (if-let [bdir (:basedir *locs)] bdir .)] ...) i.e bdir assumes the value

Re: if-let

2009-02-08 Thread Adrian Cuthbertson
:47 schrieb Adrian Cuthbertson: Here's one, I'm setting basedir to either :basedir in a map in *locs (a thread-local var) or to . if :basedir was not found in the map... (let [basedir (if-let [bdir (:basedir *locs)] bdir .)] ...) i.e bdir assumes the value of the test

unsupported binding form for cond-let

2008-12-05 Thread Brian Doyle
I started to play with cond-let in the contrib.cond package and got an unexpected error: user= (cond-let [x (zero? 0)] (println hello world)) java.lang.Exception: Unsupported binding form: (zero? 0) (NO_SOURCE_FILE:11) user= (cond-let x (zero? 0) (println hello world)) hello world Maybe

Re: unsupported binding form for cond-let

2008-12-05 Thread Stephen C. Gilardi
On Dec 5, 2008, at 1:33 PM, Brian Doyle wrote: I started to play with cond-let in the contrib.cond package and got an unexpected error: user= (cond-let [x (zero? 0)] (println hello world)) java.lang.Exception: Unsupported binding form: (zero? 0) (NO_SOURCE_FILE:11) I updated cond-let

Re: let accepting a vector

2008-11-13 Thread mb
Hi, On 13 Nov., 07:27, Larrytheliquid [EMAIL PROTECTED] wrote: Is there a way to pass a vector to a function like let, rather than manually typing in the brackets? let is not a function, but a special form (see: http://clojure.org/special_forms). It is only possible via eval to achieve

let accepting a vector

2008-11-13 Thread Larrytheliquid
Is there a way to pass a vector to a function like let, rather than manually typing in the brackets? ;;; normal let (let [one 1] one) ;;; list let (def bindings-list '[one 1]) (list-let bindings-list one) -- Respectfully, Larry Diehl www.larrytheliquid.com

Re: let accepting a vector

2008-11-13 Thread Rich Hickey
be trying anything trickier. That said, and I'm loath to show this, the original example begs the conflation of compile and runtime. Here's how to do it without eval: ; gross - please don't write code like this!!! (def bindings-list '[one 1]) (defmacro list-let a horrible macro that expects

Error message for malformed let

2008-10-04 Thread Hans Hübner
(let [a 1 b] true) yields java.lang.ArrayIndexOutOfBoundsException: 3 (NO_SOURCE_FILE:0) A syntax error would be good. -Hans --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group

Re: Error message for malformed let

2008-10-04 Thread Rich Hickey
On Oct 4, 4:23 pm, Hans Hübner [EMAIL PROTECTED] wrote: (let [a 1 b] true) yields java.lang.ArrayIndexOutOfBoundsException: 3 (NO_SOURCE_FILE:0) A syntax error would be good. I've improved the error handling for this, thanks for the report. Rich

<    2   3   4   5   6   7