loop recur vs recursion
Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct --~--~-~--~~~---~--~~ 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: loop recur vs recursion
the jvm does not do TCO, loop/recur allows for functional looking recursion on the jvm with constant stack size. On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote: Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: loop recur vs recursion
In this case, the depth of the recursion would be at maximum 21 (number of different types of amino acids), and the function itself not often called. Is stack size something to worry about at those depths? On Nov 29, 11:11 am, Kevin Downey [EMAIL PROTECTED] wrote: the jvm does not do TCO, loop/recur allows for functional looking recursion on the jvm with constant stack size. On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote: Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: loop recur vs recursion
Even if you don't think you'll run into the possibility of blowing your stack, it's still a good idea to use recur when doing tail call recursion. The compiler will help you out by making sure it really is a tail call. Remember, recur isn't just for loop. It works with functions too. On Sat, Nov 29, 2008 at 6:42 AM, bOR_ [EMAIL PROTECTED] wrote: In this case, the depth of the recursion would be at maximum 21 (number of different types of amino acids), and the function itself not often called. Is stack size something to worry about at those depths? On Nov 29, 11:11 am, Kevin Downey [EMAIL PROTECTED] wrote: the jvm does not do TCO, loop/recur allows for functional looking recursion on the jvm with constant stack size. On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote: Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
NullPointer when just returning nil?
Hi, is this the intended behavior? user= #(nil) java.lang.NullPointerException (NO_SOURCE_FILE:12) user= (def b #(nil)) java.lang.NullPointerException (NO_SOURCE_FILE:13) This works: user= #('nil) #user$eval__43$fn__45 [EMAIL PROTECTED] Thanks, -Ralf --~--~-~--~~~---~--~~ 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: NullPointer when just returning nil?
On Nov 29, 5:29 pm, Ralf Bensmann [EMAIL PROTECTED] wrote: Hi, is this the intended behavior? user= #(nil) java.lang.NullPointerException (NO_SOURCE_FILE:12) user= (def b #(nil)) java.lang.NullPointerException (NO_SOURCE_FILE:13) This is expected. #(nil) is the same as (fn [] (nil)) and hence the failure. (fn [] nil) is what you want. This works: user= #('nil) #user$eval__43$fn__45 [EMAIL PROTECTED] I am not very clear on whats happening here to comment. Parth Thanks, -Ralf --~--~-~--~~~---~--~~ 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: loop recur vs recursion
On Nov 29, 2008, at 6:49 AM, Daniel Renfer wrote: Even if you don't think you'll run into the possibility of blowing your stack, it's still a good idea to use recur when doing tail call recursion. The compiler will help you out by making sure it really is a tail call. Remember, recur isn't just for loop. It works with functions too. In case that isn't clear, it means that anywhere you would do a self call in a tail position you can replace it with recur to ensure no stack growth, e.g. the first example could have been written: (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (recur (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) recur will goto the nearest enclosing loop or fn. Rich On Sat, Nov 29, 2008 at 6:42 AM, bOR_ [EMAIL PROTECTED] wrote: In this case, the depth of the recursion would be at maximum 21 (number of different types of amino acids), and the function itself not often called. Is stack size something to worry about at those depths? On Nov 29, 11:11 am, Kevin Downey [EMAIL PROTECTED] wrote: the jvm does not do TCO, loop/recur allows for functional looking recursion on the jvm with constant stack size. On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote: Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: NullPointer when just returning nil?
But #(...) and (fn [] ...) should be the same? On Sat, Nov 29, 2008 at 1:48 PM, Parth Malwankar [EMAIL PROTECTED]wrote: On Nov 29, 5:29 pm, Ralf Bensmann [EMAIL PROTECTED] wrote: Hi, is this the intended behavior? user= #(nil) java.lang.NullPointerException (NO_SOURCE_FILE:12) user= (def b #(nil)) java.lang.NullPointerException (NO_SOURCE_FILE:13) This is expected. #(nil) is the same as (fn [] (nil)) and hence the failure. (fn [] nil) is what you want. This works: user= #('nil) #user$eval__43$fn__45 [EMAIL PROTECTED] I am not very clear on whats happening here to comment. Parth Thanks, -Ralf --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Reader Anomaly?
Hi, What happened here? user= (take 20 (interpose '.' The quick brown fox)) (\T . \h . \e . \space . \q . \u . \i . \c . \k . \space .) Naturally, I meant to use a character literal as the first argument to interpose, but my C / Java habits led me to use the apostrophes instead of the proper character literal notation. Is it a reader bug? (That the second apostrophe appeared to be ignored.) Randall Schulz --~--~-~--~~~---~--~~ 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: NullPointer when just returning nil?
On Saturday 29 November 2008 06:27, Ralf Bensmann wrote: Thanks for clarification. But I am wondering about a function can return nil: user= (fn [] ((+ 1 2) nil)) #user$eval__63$fn__65 [EMAIL PROTECTED] But just returning nil is not ok? user= (fn [] (nil)) You're not returning nil, you're trying to apply nil (as if it were a function) to an empty argument list. java.lang.NullPointerException (NO_SOURCE_FILE:24) user= (fn [] ((nil))) java.lang.NullPointerException (NO_SOURCE_FILE:25) Now you're trying to apply the result of applying nil to an empty argument list to an empty argument list. Naturally, it fails at the same point, which is the inner attempt. It's just simpler than you're trying to make it: user= ((fn [] nil)) nil Thanks -Ralf Randall Schulz --~--~-~--~~~---~--~~ 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: Reader Anomaly?
Hi, On 29 Nov., 15:30, Randall R Schulz [EMAIL PROTECTED] wrote: Hi, What happened here? String literals evaluate to themselves. Quoting prevents evaluation. When you evaluate a quoted string, you get just the string. user= 'hello hello user= hello hello user= (= a 'a) true This behaviour is similar to that of number literals. user= (= 3 '3) true hth, Robert Pfeiffer --~--~-~--~~~---~--~~ 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: NullPointer when just returning nil?
Argl... just forgot one of the basic rules ;) On Sat, Nov 29, 2008 at 3:33 PM, Randall R Schulz [EMAIL PROTECTED] wrote: On Saturday 29 November 2008 06:27, Ralf Bensmann wrote: Thanks for clarification. But I am wondering about a function can return nil: user= (fn [] ((+ 1 2) nil)) #user$eval__63$fn__65 [EMAIL PROTECTED] But just returning nil is not ok? user= (fn [] (nil)) You're not returning nil, you're trying to apply nil (as if it were a function) to an empty argument list. java.lang.NullPointerException (NO_SOURCE_FILE:24) user= (fn [] ((nil))) java.lang.NullPointerException (NO_SOURCE_FILE:25) Now you're trying to apply the result of applying nil to an empty argument list to an empty argument list. Naturally, it fails at the same point, which is the inner attempt. It's just simpler than you're trying to make it: user= ((fn [] nil)) nil Thanks -Ralf Randall Schulz --~--~-~--~~~---~--~~ 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: Reader Anomaly?
On Nov 29, 2008, at 9:30 AM, Randall R Schulz wrote: Is it a reader bug? (That the second apostrophe appeared to be ignored.) It wasn't ignored. It quoted the string. I've been interested in a way to see what the reader returns for things like this in the past. It turns out we can get that using macroexpand: user= (prn (macroexpand '(interpose '.' The quick brown fox))) (interpose (quote .) (quote The quick brown fox)) (I hadn't thought of macroexpand expanding reader macros as well as non-reader macros, but that's the effect here.) --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 -~--~~~~--~~--~--~---
Compiler bug with package name vs. namespace name
There is a bug in the AOT compiler. When it calls the method functions it uses the java package name instead of the clojure namespace name. This creates problems if I have a namespace with a dash in the name. (ns net.cddr.foo-bar1) (defn -main [] (println Hello: foo-bar1)) Compiling this and running it results in Exception in thread main java.lang.UnsupportedOperationException: net.cddr.foo_bar1/-main not defined. While this works: (ns net.cddr.foo_bar2) (defn -main [] (println Hello: foo_bar2)) --~--~-~--~~~---~--~~ 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: Reader Anomaly?
On Saturday 29 November 2008 06:45, Stephen C. Gilardi wrote: On Nov 29, 2008, at 9:30 AM, Randall R Schulz wrote: Is it a reader bug? (That the second apostrophe appeared to be ignored.) It wasn't ignored. It quoted the string. Yeah, Robert made me see that. I've been interested in a way to see what the reader returns for things like this in the past. It turns out we can get that using macroexpand: user= (prn (macroexpand '(interpose '.' The quick brown fox))) (interpose (quote .) (quote The quick brown fox)) (I hadn't thought of macroexpand expanding reader macros as well as non-reader macros, but that's the effect here.) I think the reader is doing expanding on reader macros. Macro-expand is just nilpotent when no macros are in play. In this case, it's no different than just printing the list you passed to macroexpand: user= '(interpose '.' The quick brown fox) (interpose (quote .) (quote The quick brown fox)) It's a good technique, though, to see what the compiler is going to be asked to translate after all players between the form as submitted and the compiler have done their thing. --Steve Randall Schulz --~--~-~--~~~---~--~~ 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: Reader Anomaly?
On Nov 29, 2008, at 9:55 AM, Randall R Schulz wrote: In this case, it's no different than just printing the list you passed to macroexpand: user= '(interpose '.' The quick brown fox) (interpose (quote .) (quote The quick brown fox)) It's a good technique, though, to see what the compiler is going to be asked to translate after all players between the form as submitted and the compiler have done their thing. Right you are on both counts. Thanks very much! --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 -~--~~~~--~~--~--~---
Re: loop recur vs recursion
As often as this comes up, I wonder if TCO and loop/recur deserve their own section in the reference section. Bill On Nov 29, 4:11 am, Kevin Downey [EMAIL PROTECTED] wrote: the jvm does not do TCO, loop/recur allows for functional looking recursion on the jvm with constant stack size. On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote: Hi all, I wondered if there is a difference between using loop-recur or merely writing a recursive function. The main difference I found thus far was that the loop-recur can suffice with less arguments, but the recursive functions seem to be shorter, and perhaps more elegant? (defn construct-atom translates a number n into an set of letters of size n [construct length] (if ( (count construct) length) (construct-atom (conj construct (char (+ (rand-int amino_acids) 65))) length) construct)) (defn construct-atom-loop translates a number n into an set of letters of size n [n] (let [base_construct #{}] (loop [construct base_construct] (if ( (count construct) n) (recur (conj construct (char (+ (rand-int amino_acids) 65 construct -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Macroexpand As A Tool For Understanding [was: Re: Reader Anomaly?]
On Saturday 29 November 2008 06:55, Randall R Schulz wrote: ... It's a good technique, though, to see what the compiler is going to be asked to translate after all players between the form as submitted and the compiler have done their thing. Or is it? Can you tell what a newbie I am? I'm working my way through Stuart H.'s book. I'm on the sequence section (4.2) and just got to for. Here's what I did / found: user= (doc for) - clojure.core/for ([seq-exprs expr]) Macro List comprehension. ... (take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y])) nil So seeing that for is a macro, I thought I'd see what it produces. I started with the example included in the doc string: user= (macroexpand '(take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y]))) (take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y])) So next I tried macroexpand -ing just the (for ...) sub-form: user= (macroexpand '(for [x (range 1) y (range 100) :while ( y x)] [x y])) (let* [iter__3869 (clojure.core/fn iter__33 [s__34] (clojure.core/when-first [x s__34] (if true (clojure.core/let [iterys__3867 (clojure.core/fn iter__35 [s__36] (clojure.core/when-first [y s__36] (if ( y x) (clojure.core/lazy-cons [x y] (iter__35 (clojure.core/rest s__36))) nil))) fs__3868 (iterys__3867 (range 100))] (if fs__3868 (clojure.core/lazy-cat fs__3868 (iter__33 (clojure.core/rest s__34))) (recur (clojure.core/rest s__34 nil)))] (iter__3869 (range 1))) I'm somewhat confused by this, but I gather it has something to do with take being lazy? --Steve Randall Schulz --~--~-~--~~~---~--~~ 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: NullPointer when just returning nil?
I think the NullPointerException was misleading for me... a more informational error message should be added. Rich, what do you think? On Sat, Nov 29, 2008 at 3:41 PM, Ralf Bensmann [EMAIL PROTECTED]wrote: Argl... just forgot one of the basic rules ;) On Sat, Nov 29, 2008 at 3:33 PM, Randall R Schulz [EMAIL PROTECTED]wrote: On Saturday 29 November 2008 06:27, Ralf Bensmann wrote: Thanks for clarification. But I am wondering about a function can return nil: user= (fn [] ((+ 1 2) nil)) #user$eval__63$fn__65 [EMAIL PROTECTED] But just returning nil is not ok? user= (fn [] (nil)) You're not returning nil, you're trying to apply nil (as if it were a function) to an empty argument list. java.lang.NullPointerException (NO_SOURCE_FILE:24) user= (fn [] ((nil))) java.lang.NullPointerException (NO_SOURCE_FILE:25) Now you're trying to apply the result of applying nil to an empty argument list to an empty argument list. Naturally, it fails at the same point, which is the inner attempt. It's just simpler than you're trying to make it: user= ((fn [] nil)) nil Thanks -Ralf Randall Schulz --~--~-~--~~~---~--~~ 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: Macroexpand As A Tool For Understanding [was: Re: Reader Anomaly?]
On Saturday 29 November 2008 07:29, Randall R Schulz wrote: On Saturday 29 November 2008 06:55, Randall R Schulz wrote: ... It's a good technique, though, to see what the compiler is going to be asked to translate after all players between the form as submitted and the compiler have done their thing. Or is it? ... I'm working my way through Stuart H.'s book. I'm on the sequence section (4.2) and just got to for. Here's what I did / found: ... So seeing that for is a macro, I thought I'd see what it produces. I started with the example included in the doc string: user= (macroexpand '(take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y]))) (take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y])) So next I tried macroexpand -ing just the (for ...) sub-form: user= (macroexpand '(for [x (range 1) y (range 100) :while ( y x)] [x y])) (let* [iter__3869 (clojure.core/fn iter__33 [s__34] (clojure.core/when-first [x s__34] (if true ... I'm somewhat confused by this, but I gather it has something to do with take being lazy? And, continuing my exploration, the confirmation of this hunch comes shortly after, in section 4.3. This does, at least, impose a caveat on the use of macroexpand as a tool for understanding what your code really says (and does). Randall Schulz --~--~-~--~~~---~--~~ 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: Macroexpand As A Tool For Understanding [was: Re: Reader Anomaly?]
On Nov 29, 2008, at 10:29 AM, Randall R Schulz wrote: I'm somewhat confused by this, but I gather it has something to do with take being lazy? The last note in the doc for macroexpand explains it: user= (doc macroexpand) - clojure.core/macroexpand ([form]) Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note neither macroexpand-1 nor macroexpand expand macros in subforms. nil In this first case, for is a subform. There's a nice description of going further here: http://groups.google.com/group/clojure/msg/28837d55525306d8 --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 -~--~~~~--~~--~--~---
Re: Macroexpand As A Tool For Understanding [was: Re: Reader Anomaly?]
On Saturday 29 November 2008 07:35, Stephen C. Gilardi wrote: On Nov 29, 2008, at 10:29 AM, Randall R Schulz wrote: I'm somewhat confused by this, but I gather it has something to do with take being lazy? The last note in the doc for macroexpand explains it: user= (doc macroexpand) - clojure.core/macroexpand ([form]) Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note neither macroexpand-1 nor macroexpand expand macros in subforms. nil In this first case, for is a subform. There's a nice description of going further here: http://groups.google.com/group/clojure/msg/28837d55525306d8 OK. So it's not the laziness of take, but rather the nature of macroexpand. Thanks for the reference. I'll review that post. --Steve Randall Schulz --~--~-~--~~~---~--~~ 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: Exception on the formatted print method calls
On Nov 29, 2008, at 10:48 AM, ppierre wrote: But I can't compile core.clj when I put get-locale and with-locale inside it. What error do you get? - *locale* (should be set!-able as well), A set-locale function ? No, I meant that if *locale* becomes part of Clojure at some point, it should be added to the list of bindings that are customarily pushed around a repl or script so they always have thread-local bindings that can be set with set! . See clojure.main/with-bindings for other examples. Please see clojure.org/contributing for info about what it would take for your code to be eligible for inclusion in Clojure or clojure- contrib. I encourage you (and everyone interested in contributing code) to send in the contributor agreement so things you come up with can be considered. What do you have in mind for the several cases in get-locale with one argument? --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 -~--~~~~--~~--~--~---
Re: Trying to get the ants demo to run on Windows
Hi there, I'm having almost the same problem. I'm trying to get the ants demo running in ubuntu, and I get Rob's second problem: user= (def panel (doto (proxy [JPanel] [] (paint [g] (render g))) (.setPreferredSize (new Dimension (* scale dim) (* scale dim) java.lang.IllegalArgumentException: No matching method found: .setPreferredSize for class clojure.lang.Proxy__203 (NO_SOURCE_FILE:7) The rest of the file loads - if I run clojure from within slime I can individually compile the rest of the defns. (That said, I can no longer start clojure from within slime. After updating clojure it stopped working.) I'm at revision 1128 for clojure. I'm new to Java, so is it possible that I don't have some Swing/AWT thing installed? No complaint from: user= (import '(java.awt Color Graphics Dimension) '(java.awt.image BufferedImage) '(javax.swing JPanel JFrame)) nil And, the java version, in case that's relevant: [EMAIL PROTECTED]:~$ java -version java version 1.6.0_07 Java(TM) SE Runtime Environment (build 1.6.0_07-b06) Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing) Any ideas? Thanks, Blaine --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Documentation of :: Notation?
Hi, I came across the use of :: keyword notation in section 8.4 of Programming Clojure (beta 3 PDF) and went to look for it on the Clojure Web site, but it appears not to be mentioned there. I looked in the Reader, Evaluation, Namespaces, API, Multimethods ('cause that's where Stuart introduces it in his book) and even the Differences with other Lisps pages. Is it there somewhere I'm not seeing (or looking for) it? Randall Schulz --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Possible Reflector Bug
Consider these 2 interfaces: - PackagePrivateInterface.java package test; interface PackagePrivateInterface { public void myPublicMethod(); } - PublicTagInterface.java package test; public interface PublicTagInterface extends PackagePrivateInterface { } And these 2 classes: - Factory.java package test; public class Factory { public static PublicTagInterface newImpl() { return new PackagePrivateClass(); } } - PackagePrivateClass.java package test; class PackagePrivateClass implements PublicTagInterface { PackagePrivateClass(){ } public void myPublicMethod() { } } Now examine the following snippet of clojure code: (import '(test Factory PublicTagInterface)) (def foo (. Factory newImpl)) (. foo myPublicMethod) java.lang.IllegalAccessException: Class clojure.lang.Reflector can not access a member of class test.PackagePrivateInterface with modifiers public abstract (NO_SOURCE_FILE:0) Also can not should be spelled cannot. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Next: #=(...) [was: Re: Documentation of :: Notation?]
Thanks, Stuart, On Saturday 29 November 2008 15:04, Stuart Halloway wrote: The only place I have seen it is on this list, when I asked Rich how to get the code for that section of the book to work. :-) OK... Is it a legitimate part of Clojure's public specification, or is it something that is (even more) subject to change (than other things in a young language)? I've read the whole book now, and the only other unexplained notation I've found is #=. The first appearance is on page 57 (use fixed-width for optimum viewing)): (meta #'meta) - {:arglists ([obj]), :name meta, :file boot.clj, :line 147, :ns #=(find-ns clojure), ^^^ :doc ...} I can't replicate this by evaluating (meta #'meta). What I see in that place is :ns #Namespace clojure.core. And while I find a place in the Clojure code that emits the #= sequence, it's part of an undocumented defmethod. What does it mean? Is it meant to be readable? If I try to read that, I get this (in a newly launched REPL): user= #=(find-ns clojure) nil By the way, I should point out I'm using the latest SVN revision of the Clojure code. Stuart ... Randall Schulz --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Getting Started question
On Windows, when I enter the following line from Getting Started into the REPL, nothing happens... it just hangs: (. javax.swing.JOptionPane (showMessageDialog nil Hello World)) Any idea why this isn't working for me? Also, has anyone written a more detailed guide to getting up and running on a Windows system. It sounds like the main editor people are using is Emacs, with other modes (and what exactly is Slime?). Anyone have a step-by-step guide to getting this stuff operational? Is Enclojure ready for prime-time? On Windows? Looking forward to trying more Clojure, Mark --~--~-~--~~~---~--~~ 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: Next: #=(...) [was: Re: Documentation of :: Notation?]
On Saturday 29 November 2008 17:00, Chouser wrote: On Sat, Nov 29, 2008 at 6:26 PM, Randall R Schulz wrote: OK... Is it a legitimate part of Clojure's public specification, or is it something that is (even more) subject to change (than other things in a young language)? The double-colon keyword prefix is a specific and supported feature, I believe, introduced Jul 28, svn rev 962. Since this predates the last release, I assume the lack of documentation is a simple oversight. The details were posted to this group here: http://groups.google.com/group/clojure/browse_frm/thread/9cc9926de1bdb128 I've read the whole book now, and the only other unexplained notation I've found is #=. This is part of the print-dup work related to AOT. It is new since the last release, and therefore not necessarily documented on the site yet. ... Hope that helps make sense of things, --Chouser Thanks, Stuart and Chris (it's Chris, right?). As the programming language that is Clojure seeps into my mind, I realize what a beautiful thing it is. As I said to a friend a couple of days ago, I'd demurred too long in choosing a language for the extension / scripting / executive layer for my theorem prover, but when I finally realized that Clojure was the way to go and started digging in to the language and contemplated the design for that new addition to my system, I quickly realized the tremendous power that Clojure brings. Thanks to Rick H. and everyone else who has contributed to making Clojure what it is now and what it will become over time. Randall Schulz --~--~-~--~~~---~--~~ 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: Getting Started question
On Saturday 29 November 2008 17:28, puzzler wrote: On Windows, when I enter the following line from Getting Started into the REPL, nothing happens... it just hangs: (. javax.swing.JOptionPane (showMessageDialog nil Hello World)) Any idea why this isn't working for me? Is it possible that the message alert / dialog / window is simply being opened behind the one in which you're running the Clojure REPL? Also, it's probably prudent to be running a recent release of either version 1.5 or 1.6 of Sun's JVM / JDK. Also, has anyone written a more detailed guide to getting up and running on a Windows system. It sounds like the main editor people are using is Emacs, with other modes (and what exactly is Slime?). Anyone have a step-by-step guide to getting this stuff operational? I don't use Emacs (nor do I use Windows for my programming work), but since the REPL is itself purely character-oriented, there should be no real problem using it on Windows. Cygwin (http://cygwin.com/) is always highly recommended for programmers saddled with Windows! SLIME is an Emacs-based development environment for programming Lisp under Emacs (technically, The Superior Lisp Interaction Mode for Emacs). You might want to check out Like Slime, for Vim: http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/. Is Enclojure ready for prime-time? On Windows? I'm not really qualified to say, but I will anyway: YES! But seriously, insofar as Java and Swing are fully supported and co-equal for Windows, MacOS and Linux, Clojure is likewise fully supported on all three platforms. Looking forward to trying more Clojure, Mark Randall Schulz --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
SVN or release?
Hi all, I've been playing with Clojure for a few days now, following the mailing list, searching and tinkering, etc. I'm really excited about this language! I'm running the latest packaged release, and I'd like to start writing some more serious spikes in Clojure, but I'm starting to get the impression that I should be using the SVN version instead to get the latest hotness. I say this because I've noticed a few things here and there in 3rd party code and in the docs that are not working, it seems, because they depend on features/changes only present in SVN, such as the Java method call operators, and some namespace shuffling. Being a Vimmer, for example, I tried to set up Chimp and am getting a mysterious exception from the STM's innards when Vim tries to connect to Chimp's REPL listener. Is there a general recommendation here? Should I be on SVN or is this just my bad luck :) Thanks, -Kyle --~--~-~--~~~---~--~~ 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: Getting Started question
On Nov 29, 5:39 pm, Randall R Schulz [EMAIL PROTECTED] wrote: On Saturday 29 November 2008 17:28, puzzler wrote: SLIME is an Emacs-based development environment for programming Lisp under Emacs (technically, The Superior Lisp Interaction Mode for Emacs). You might want to check out Like Slime, for Vim: http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/. That article makes Slime sound pretty good. Still seems a bit tricky to get emacs/slime/clojure up and running on windows. Any step-by- step instructions would be appreciated. --Mark --~--~-~--~~~---~--~~ 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: SVN or release?
Kyle Schaffrick wrote: Hi all, I've been playing with Clojure for a few days now, following the mailing list, searching and tinkering, etc. I'm really excited about this language! I'm running the latest packaged release, and I'd like to start writing some more serious spikes in Clojure, but I'm starting to get the impression that I should be using the SVN version instead to get the latest hotness. I say this because I've noticed a few things here and there in 3rd party code and in the docs that are not working, it seems, because they depend on features/changes only present in SVN, such as the Java method call operators, and some namespace shuffling. Being a Vimmer, for example, I tried to set up Chimp and am getting a mysterious exception from the STM's innards when Vim tries to connect to Chimp's REPL listener. Is there a general recommendation here? Should I be on SVN or is this just my bad luck :) I think Rich is working towards a 1.0. For now I prefer to follow svn HEAD. Its best to check the svn release log before using just in case there are any intermediate checkins. These are typically marked Interim checkin - DO NOT USE!! in the log. I plan to stick to releases post 1.0. Regarding Chimp, maybe you can try Gorilla: http://groups.google.com/group/clojure/browse_thread/thread/c8b7bc3106c39791 I haven't used it personally yet. Parth Thanks, -Kyle --~--~-~--~~~---~--~~ 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: Getting Started question
Sounds great, but the link to the installer given in that thread is broken :( . On Nov 29, 7:11 pm, Mark Feeney [EMAIL PROTECTED] wrote: Clojure Box, alpha thread:http://groups.google.com/group/clojure/browse_frm/thread/6fd17fb97f05... --~--~-~--~~~---~--~~ 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: SVN or release?
On Sat, 29 Nov 2008 19:05:23 -0800 (PST) Parth Malwankar [EMAIL PROTECTED] wrote: Regarding Chimp, maybe you can try Gorilla: http://groups.google.com/group/clojure/browse_thread/thread/c8b7bc3106c39791 I haven't used it personally yet. My mistake, I actually did mean Gorilla and not Chimp. In any case, thanks for everyone's input. Since there's a 1.0 on the horizon I'll standby for that and continue my tinkering with this release. :) -Kyle --~--~-~--~~~---~--~~ 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: infix operators
As most people will tell you, the prefix notation is more natural in Lisp-like languages. However, I sometimes wonder if adding a Haskell infix operator (grave accent changes the argument order) could be a good idea in some situations; for example (2 `+ 3) - (+ 2 3). On Nov 28, 3:54 pm, Dmitri [EMAIL PROTECTED] wrote: First of I'd like to say that I find Clojure to be an excellent language, however I find the lack of infix operators makes reading equations somewhat unnatural, eg: (+ (- (* x x) (* y y)) a) I ended up writing a simple function to handle infix notation (defn infix [arg1 func arg2 args] (let [result (func arg1 arg2)] (if (= args nil) result (recur result (first args) (second args) (rrest args) using that I find makes the code more readable: (infix (infix x * x) - (infix y * y) + a) I was wondering if there is a more elegant way to do this, and if it could be added as a standard or contrib function. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---