Re: Does anyone need any clojure work done?
On Jul 7, 10:18 pm, ataggart alex.tagg...@gmail.com wrote: After having spent the last decade doing server-side java, lots of infrastructure level code which I enjoy), and going blind on xml, I'd really like to get more into clojure. I've been playing with it off and on for about a year now, reading whatever FP-related material I can get my hands on, but without a real project to work on it's all been a bit aimless. To get more serious about it I'd need to work on an actual problem to solve. To that end, if anyone has a project they'd like help on, be it open or closed, paid or not, please let me know. Talk to Jon Harrop. He just asked for help with his ray tracer. Also all the shootout needs porting to Clojure. Beware the frequently bad tempered admin though. --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
On Jul 7, 5:10 pm, John Harrop jharrop...@gmail.com wrote: Problem: Passing primitives from an inner loop to an outer loop efficiently. Here is what I've found. The fastest method of result batching, amazingly, is to pass out a list and: (let [foo (loop ... ) x (double (first foo)) r1 (rest foo) y (double (first r1)) r2 (rest r1) z (double (first r2))] ... ) This isn't suprising if you think about it. In the list situation you are just grabbing the next pointer, in an array situation you have to do math to access a vector. (here passing out three doubles). About half as fast is: (let [[x y z] (loop ... )] ... ) with (double x), (double y), and (double z) used later in place of x y z and only one occurrence of each (so no more (double foo) conversions than before). The destructuring bind apparently exerts a higher run-time overhead compared to manual destructuring. If you look at the source code this isn't that surprising. The big difference between (for example): (let [[x y z] [1 2 3]] ...) and (let [v [1 2 3] x (v 0) y (v 1) z (v 2)] ...) Most of the slowdown Seems to have to do with bounds checking: The first is 'safe' and returns nil for out of bounds, the second throws an exception. but If you look at the source the 2ary version of nth gets inlined and the 3ary version (which destructuring bind expands to) does not. and if you put a symbol in the second position you'll note that Destructuring bind rebinds the symbol with a Gensym even though it cannot suffer from multiple evaluation. If you look here: http://gnuvince.wordpress.com/2009/05/11/clojure-performance-tips/ And look at 'avoid destructuring binding for vectors' I did some hacking and improved the worst case from about 500ms on my computer to 300ms. (By inlining the 3ary version and removing the duplication; compiling a destructuring function without bounds checking breaks compilation for obvious reasons...). There are probably better ways to optimize it as this was just me screwing around ('What can i break this evening?'). I will note that there is something very funny going on with the destructuring/binding example in the link above. The fast version on my machine returns every number of times(1e7 1e8 1e9 etc...) returns 26 ms. It is kind of like it all just got collapsed into a constant. --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
If result is a vector v, then from these 4 cases: (let [v [1 2 3]] (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z)) using 'nth' (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) is the fastest. Frantisek On Jul 7, 11:10 pm, John Harrop jharrop...@gmail.com wrote: Problem: Passing primitives from an inner loop to an outer loop efficiently. Here is what I've found. The fastest method of result batching, amazingly, is to pass out a list and: (let [foo (loop ... ) x (double (first foo)) r1 (rest foo) y (double (first r1)) r2 (rest r1) z (double (first r2))] ... ) (here passing out three doubles). About half as fast is: (let [[x y z] (loop ... )] ... ) with (double x), (double y), and (double z) used later in place of x y z and only one occurrence of each (so no more (double foo) conversions than before). The destructuring bind apparently exerts a higher run-time overhead compared to manual destructuring. (with-locals [x (double 0) y (double 0) z (double 0)] (loop ... ) (do-something-with (double (var-get x)) (double (var-get y)) (double (var-get z is two full orders of magnitude slower (here the loop doesn't return a list but uses var-set). Using atoms is even worse. (let [#^doubles xyz (double-array (int 3))] (loop ... ) (do-something-with (aget xyz (int 0)) (aget xyz (int 1)) (aget xyz (int 2 with the loop using aset-double to pass out values is, surprisingly, no faster. Using plain aset makes no difference, as does removing the (int ...) wrappings around the numbers. Intermediate in speed is using a clojure vector to pass out values, e.g. [result-x result-y result-z] is the expression that returns a value from the loop, and (do-something-with (get results (int 0)) (get results (int 1)) (get results (int 2))) It's surprising that this is faster than using a primitive Java array with type-hints, and interesting that retrieving sequential items from a list is faster than a like number of in-order indexed retrievals from a vector, which could theoretically be optimized to a pointer-walk with each retrieval involving an increment and a dereference and a store, rather than an increment, three dereferences, and a store. (Dereference linked list entry item pointer, store, increment pointer, dereference to get next-entry pointer, dereference again, repeat.) Whatever, these results may be useful to someone, along with: (defn- extract-result-list-into [conv hint gensyms result-generator] (let [rs (take (count gensyms) (repeatedly gensym))] (into [(first rs) result-generator] (loop [r rs g (if hint (map #(with-meta % {:tag hint}) gensyms) gensyms) output []] (if (empty? r) output (let [fr (first r) rr (rest r) frr (first rr)] (recur (rest r) (rest g) (into output (concat [(first g) (if conv `(~conv (first ~fr)) `(first ~fr))] (if frr [frr `(rest ~fr)])) This helper function can be used in a macro to suck the contents of a list into variables with conversions, type hints, or both; conv would be a symbol like `double, hint something like BigInteger, gensyms some gensyms (or other symbols) for the variable names (in order), and result-generator some code (e.g. resulting from a backtick expression). The output is a vector resembling [G__5877 (loop ... whatever code) #^hint G__5874 (conv (first G__5877)) G_5878 (rest G__5877) #^hint G__5875 (conv (first G__5878)) G_5879 (rest G__5878) #^hint G__5876 (conv (first G__5879))] which can be used in a let, loop, or other construct that uses bindings with the usual clojure syntax, and can even have other things added to it by macro code. The downside is relative inflexibility. If you pass in a gensyms seq with an embedded vector of two gensyms you'll get a valid destructuring bind for a composite item in the results, but it won't work with type hints or conversions, nor can those be mixed. Making it more sophisticated would be possible, though. This arose when I had a performance-critical double-barreled loop to optimize, and found that the outer loop was spending several thousand iterations of the inner loop worth of time just to extract the results via with-locals. I did some experimenting and benchmarking of various ways to get the output of the inner loop to code in the outer loop, using System/nanoTime, millions of repetitions, and averaging to determine the winner. An efficient labeled recur would be nice for clojure 2.0. :) (Limited though it would be to when the inner loop was in tail position in the outer loop.) --~--~-~--~~~---~--~~ 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
Save current namespace like a Smalltalk image
Hello, Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some workspace image and pick up where I left off. Rob --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Robert, On Jul 8, 2009, at 2:13 AM, Robert Campbell wrote: Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some workspace image and pick up where I left off. Something similar was discussed recently but didn't come to a solid conclusion: http://groups.google.com/group/clojure/browse_thread/thread/4efaee2e67a272c6/f24578bfa06e6b9c?lnk=gstq=printing+and+reading+a+function#f24578bfa06e6b9c This is kind of a cop-out, but in general my advice would be to work from a file. Get your Clojure and Emacs set up so that you can compile your stuff pretty easily and your files are in the namespace- appropriate folder underneath your classpath. For example, I keep my Clojure code in ~/Projects/Languages/Clojure and my Emacs config looks like this: (setq swank-clojure-extra-classpaths (cons /Users/fusion/Projects/Languages/Clojure/classes (cons /Users/fusion/Projects/Languages/Clojure (directory-files ~/.clojure t \.jar$ (eval-after-load 'clojure-mode '(clojure-slime-config)) (setq swank-clojure-extra-vm-args '(-Dclojure.compile.path=/Users/ fusion/Projects/Languages/Clojure/classes)) Now if I want to load or compile a Clojure file, it just works. Next, when I start doodling I make a file in the aforementioned directory and put my stuff in there and open up a slime session in another window. C-c C-c sends the current form over Slime to the running session. Then I do my interactive testing and exploration in the slime session. Whenever I hit on a form I want to keep, I copy and paste it over to the file and make it into a function over there. I might make a function with a dumb name like demo or test and put a bunch of forms in there, and eventually they get refactored into unit tests (or not). If I close Emacs and reopen it on a file that doesn't yet have a namespace and whatnot, I select the stuff I want to evaluate and do C-c C-r to evaluate the region. It's handy, if less transparent. The main advantage to this, apart from keeping the code clean, is that you avoid the dirty image problem that can happen with Common Lisp or (I assume) Smalltalk, where the code seems to work but accidentally depends on cruft in the image that never made it into the source file. I've had this happen in CL and found it very frustrating. I had a tumblog which I tried to make faster by saving images and found one day to my surprise that I couldn't make a fresh image on my server, which was running a different architecture, because the only reason it was able to make images on my box was because the first image had some crap in it that never made it to the source file. Maybe this problem isn't as prevalent in Smalltalk; maybe the JVM can circumvent this by being cross-platform, but it's happened more than once in CL. IIRC, CMU CL for a long time was self-hosting to such a degree it couldn't be built at all without a running binary of a previous version. That kind of thing makes porting to new architectures quite difficult. Just my $0.02, — Daniel Lyons --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Thanks Daniel, that makes perfect sense, especially about having random - and forgotten - code in the image. I have a lot of this during my exploration sessions. The main reason this is an issue for me is during development I sometimes find I need another library added to my classpath. Right now the only way I know how to modify the classpath in Emacs is to change the .emacs file with an add-to-list 'swank-clojure-extra-classpaths and reboot. I think my looking for an image solution might be a cop-out itself; I need to learn Emacs better so I can figure out how to modify the classpath without rebooting. Then I wouldn't be rebooting so often and I wouldn't need to be making images to save I'm-in-the-middle-of-a-thought state On Wed, Jul 8, 2009 at 10:57 AM, Daniel Lyonsfus...@storytotell.org wrote: Robert, On Jul 8, 2009, at 2:13 AM, Robert Campbell wrote: Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some workspace image and pick up where I left off. Something similar was discussed recently but didn't come to a solid conclusion: http://groups.google.com/group/clojure/browse_thread/thread/4efaee2e67a272c6/f24578bfa06e6b9c?lnk=gstq=printing+and+reading+a+function#f24578bfa06e6b9c This is kind of a cop-out, but in general my advice would be to work from a file. Get your Clojure and Emacs set up so that you can compile your stuff pretty easily and your files are in the namespace- appropriate folder underneath your classpath. For example, I keep my Clojure code in ~/Projects/Languages/Clojure and my Emacs config looks like this: (setq swank-clojure-extra-classpaths (cons /Users/fusion/Projects/Languages/Clojure/classes (cons /Users/fusion/Projects/Languages/Clojure (directory-files ~/.clojure t \.jar$ (eval-after-load 'clojure-mode '(clojure-slime-config)) (setq swank-clojure-extra-vm-args '(-Dclojure.compile.path=/Users/ fusion/Projects/Languages/Clojure/classes)) Now if I want to load or compile a Clojure file, it just works. Next, when I start doodling I make a file in the aforementioned directory and put my stuff in there and open up a slime session in another window. C-c C-c sends the current form over Slime to the running session. Then I do my interactive testing and exploration in the slime session. Whenever I hit on a form I want to keep, I copy and paste it over to the file and make it into a function over there. I might make a function with a dumb name like demo or test and put a bunch of forms in there, and eventually they get refactored into unit tests (or not). If I close Emacs and reopen it on a file that doesn't yet have a namespace and whatnot, I select the stuff I want to evaluate and do C-c C-r to evaluate the region. It's handy, if less transparent. The main advantage to this, apart from keeping the code clean, is that you avoid the dirty image problem that can happen with Common Lisp or (I assume) Smalltalk, where the code seems to work but accidentally depends on cruft in the image that never made it into the source file. I've had this happen in CL and found it very frustrating. I had a tumblog which I tried to make faster by saving images and found one day to my surprise that I couldn't make a fresh image on my server, which was running a different architecture, because the only reason it was able to make images on my box was because the first image had some crap in it that never made it to the source file. Maybe this problem isn't as prevalent in Smalltalk; maybe the JVM can circumvent this by being cross-platform, but it's happened more than once in CL. IIRC, CMU CL for a long time was self-hosting to such a degree it couldn't be built at all without a running binary of a previous version. That kind of thing makes porting to new architectures quite difficult. Just my $0.02, — Daniel Lyons --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using Clojure for complex database driven applications
Hello, So we are going to develop a moderately complex Database driven application in Clojure and I am looking for easy-to-manage solutions for talking to Databases. I am quite used to the way Object Relational Mappers like SQLAlchemy Django work in the Python world. We define the DB schema using simple classes and then we access and manipulate the DB using objects and their properties/methods. I would prefer a similar setup for Clojure as I would rather not deal with any kind of raw SQL. I am also a Java newbie; and I am currently looking at Hibernate (and may be Spring to make Hibernate less verbose). I would like to know how you have solved similar problems. Is Hibernate useful? Is managing a bunch of XML config files a necessary evil? Any help will be appreciated. Regards, BG -- Baishampayan Ghose b.gh...@ocricket.com oCricket.com signature.asc Description: OpenPGP digital signature
Re: Using Clojure for complex database driven applications
Take a look at ClojureQL http://github.com/Lau-of-DK/clojureql/tree/master It's not a ORM system like SQLAlchemy/Django ORM in that it won't manage the table schema for you. There is also clj-record. http://github.com/duelinmarkers/clj-record/tree/master which is inspired by rail's ActiveRecord. On Wed, Jul 8, 2009 at 5:59 AM, Baishampayan Ghoseb.gh...@ocricket.com wrote: Hello, So we are going to develop a moderately complex Database driven application in Clojure and I am looking for easy-to-manage solutions for talking to Databases. I am quite used to the way Object Relational Mappers like SQLAlchemy Django work in the Python world. We define the DB schema using simple classes and then we access and manipulate the DB using objects and their properties/methods. I would prefer a similar setup for Clojure as I would rather not deal with any kind of raw SQL. I am also a Java newbie; and I am currently looking at Hibernate (and may be Spring to make Hibernate less verbose). I would like to know how you have solved similar problems. Is Hibernate useful? Is managing a bunch of XML config files a necessary evil? Any help will be appreciated. Regards, BG -- Baishampayan Ghose b.gh...@ocricket.com oCricket.com -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ 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: Using Clojure for complex database driven applications
Wilson MacGyver wrote: Take a look at ClojureQL http://github.com/Lau-of-DK/clojureql/tree/master It's not a ORM system like SQLAlchemy/Django ORM in that it won't manage the table schema for you. There is also clj-record. http://github.com/duelinmarkers/clj-record/tree/master which is inspired by rail's ActiveRecord. How mature are they? Do they work well with PostgreSQL? Apparently, ClojureQL doesn't. Regards, BG -- Baishampayan Ghose b.gh...@ocricket.com oCricket.com signature.asc Description: OpenPGP digital signature
Re: Save current namespace like a Smalltalk image
I had the same thought (as posted in the other thread) and haven't come to a final solution yet. The main reason I wanted to achieve it was that I do my developing / tinkering / brainstorming spread over several work boxes spread out through several locations, and a clojure REPL is cheap and easy, whereas maintaining several IDEs in synch (3 locations at work, 2 at home) can be a bit of a nightmare. The compromise I've got at the moment is that I've made a custom wrapper around [defn] that records the code used to create the instance, and stores it in the metadata of the var that points to the function. I can then cycle through the namespace definitions using ns- interns / ns-publics and see the definition of each function, and can save it to a file. I tried to create a print-dup method so that the entire contents of a namespace could be dumped to a file, but as chouser pointed out, print- dup works on the function itself, whereas the code is stored in the metadata of the var that points to the function (and there's no back- link from the function to the var), so now it is a multi-stage process to port current code in its entirety, but as I'm generally only working on fairly limited areas of code it isn't a huge deal. Also, any closures are not captured by capturing the source, so there's still issues there, but for me the function definition is generally good enough. Still have to implement it for macros as well, but haven't needed that as much. Incidentally, I find the easiest way to port my code around is to print it to the repl, then cut-and-paste it to etherpad, which I can then access from anywhere (without having to save). Now if only there was a hosted REPL that integrated an IDE nicely I would really be set. Lord-of-all-repls comes close, but is not pure clojure or JVM. Jurjen On Jul 8, 8:13 pm, Robert Campbell rrc...@gmail.com wrote: Hello, Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some workspace image and pick up where I left off. Rob --~--~-~--~~~---~--~~ 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: Using Clojure for complex database driven applications
I am quite used to the way Object Relational Mappers like SQLAlchemy Django work in the Python world. I've recently thought that a good project would be to port SQLAlchemy to Clojure. It wouldn't be a straight port since the languages are so different, but at least SQLAlchemy's query generation stuff against a reflected schema would be great. Maybe ClojureQL gets close to this though, I haven't worked with it enough yet to know. --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Hi Jurjen, That wrapper for defn is something I was looking for in another post; I previously asked how I can inspect the definitions of my functions on the REPL. When I'm exploring stuff I'll be redefining many functions many times and sometimes I lose track things. I basically have to scroll around searching my REPL for the last definition. It sounds like you have a solution to this problem. It seems strange to me that Clojure doesn't support this concept natively. At some point the function definition is compiled into bytecode to run on the JVM, why not just automatically safe the original definition in metadata when this is done? Have you should about adding your wrapper code to Contrib? Rob On Wed, Jul 8, 2009 at 12:30 PM, Jurjenjurjen.hait...@gmail.com wrote: I had the same thought (as posted in the other thread) and haven't come to a final solution yet. The main reason I wanted to achieve it was that I do my developing / tinkering / brainstorming spread over several work boxes spread out through several locations, and a clojure REPL is cheap and easy, whereas maintaining several IDEs in synch (3 locations at work, 2 at home) can be a bit of a nightmare. The compromise I've got at the moment is that I've made a custom wrapper around [defn] that records the code used to create the instance, and stores it in the metadata of the var that points to the function. I can then cycle through the namespace definitions using ns- interns / ns-publics and see the definition of each function, and can save it to a file. I tried to create a print-dup method so that the entire contents of a namespace could be dumped to a file, but as chouser pointed out, print- dup works on the function itself, whereas the code is stored in the metadata of the var that points to the function (and there's no back- link from the function to the var), so now it is a multi-stage process to port current code in its entirety, but as I'm generally only working on fairly limited areas of code it isn't a huge deal. Also, any closures are not captured by capturing the source, so there's still issues there, but for me the function definition is generally good enough. Still have to implement it for macros as well, but haven't needed that as much. Incidentally, I find the easiest way to port my code around is to print it to the repl, then cut-and-paste it to etherpad, which I can then access from anywhere (without having to save). Now if only there was a hosted REPL that integrated an IDE nicely I would really be set. Lord-of-all-repls comes close, but is not pure clojure or JVM. Jurjen On Jul 8, 8:13 pm, Robert Campbell rrc...@gmail.com wrote: Hello, Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some workspace image and pick up where I left off. Rob --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
It seems to me you want: user= (list + 1 2) (#core$_PLUS___4006 clojure.core$_plus___4...@1acd47 1 2) That looks like what I'm after. When I run a test, however, it doesn't behave properly: user (def my-func (list + 1 2)) #'user/my-func user (my-func) ; Evaluation aborted. clojure.lang.PersistentList cannot be cast to clojure.lang.IFn On Wed, Jul 8, 2009 at 6:06 AM, Timothy Pratleytimothyprat...@gmail.com wrote: It seems to me you want: user= (list + 1 2) (#core$_PLUS___4006 clojure.core$_plus___4...@1acd47 1 2) As opposed to: user= '(+ 1 2) (+ 1 2) Regarding examining a function, contrib has some helpers written by Chris user= (use 'clojure.contrib.repl-utils) (source func) (show func) In your case source wont be useful as the function is generated not read from source. The output from show is a bit opaque to me so not sure if it is useful to you. I think once it is compiled a function is not easy to examine... so as you alluded to the best alternative would be to keep the AST? Regards, Tim. On Jul 7, 10:18 pm, Robert Campbell rrc...@gmail.com wrote: I'm trying to write the first basic GP example in this free book:http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf I've gotten a lot of the suppor methods working correctly (like fitness) but I'm having problem convering the pseudocode on page 14 for generating random expressions to make up my initial population. Here's what I have so far: (defn gen-rand-expr [functions terminals max-depth arity method] (if (or (= max-depth 0) (and (= method :grow) ( (rand) (/ (count terminals) (+ (count terminals) (count functions)) (rand-element terminals) (let [arg1 (gen-rand-expr functions terminals (- max-depth 1) arity method) arg2 (gen-rand-expr functions terminals (- max-depth 1) arity method) func (rand-element functions)] (func arg1 arg2 First, how can I print out the definition of a function in clojure? For example, if I do (defn add [x y] (+ x y)) how can inspect this definition, like (show-def add) - (defn add [x y] (+ x y)). This would help a lot in debugging the random programs I'm trying to generate. Second, I believe the last line is the problem in my code. Let's assume the function randomly selected was +, it will run (+ 1 2) and the entire function returns 3 instead of a randomly generated syntax tree like I need. I then tried '(func arg1 arg2) hoping it would prevent evaluation, but then it will always just return (func arg1 arg2) which isn't what I need either. I need it to actually return a syntax tree made up of expressions like (+ 1 2) but unevaluated. I am guessing I need to start reading and using macros at this point? Rob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Clojure box - loading book examples from Programming Clojure
Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. [ i did my share of trying to make clojure work from cygwin and even windows command - failed to start clojure with all the libraries, had to manually create a bat file to run. Then came the indentation part, I have been typing away on one line, but is terribly messy.The biggest obstacle is indentation. I know I can edit a file and reload it, but I prefer it via the REPL] I did read about an earlier post (http://groups.google.com/group/ clojure/browse_thread/thread/0bb49e6409f43f5d/cbf20098c83215d3) but I didn't see an accepted solution to that. -dumby --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
On Wed, Jul 8, 2009 at 3:42 AM, Frantisek Sodomka fsodo...@gmail.comwrote: If result is a vector v, then from these 4 cases: (let [v [1 2 3]] (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z)) using 'nth' (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) is the fastest. Is it faster than using list and manually destructuring the list? If so, that would mean that (nth v n) is faster than (get v n), which would be odd since the latter should turn into the former anyway and be inlinable by the JIT. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Clojure cheat sheet
Hello everyone, while looking around for a modern lisp, I discovered Clojure and was instantly infected by the new possibilities to write software. Since then I watched the screencasts and read several tutorials. Finally I bought Programming Clojure by Stuart and I was impressed by his clean and well-structured writing style. There are many many great tutorials about Clojure out there, but I was interested in a summary of the available Clojure functions and macros. So I decided to hack together a Clojure cheat sheet in the style of the Latex cheat sheet by Winston Chang (http://www.stdout.org/~winston/ latex). Consequently the sheet should not contain more than two pages. At first, I though about the following arrangement: function | short description | example. Quickly I realized, that the sheet would become a book. Therefore I mostly used the categories in the Clojure Wiki on http://www.clojure.org. For example, when you are working with sequences, you can look up, which function could be used to get your things done. Most names are self-explaining and in doubt (doc function) will help you out with parameters and description. Sometimes an example for a complicated function would be useful, but in that case, you have to look up elsewhere. Sorry... You find the cheat sheet in the Clojure group file section (clojure- cheat-sheet.zip). Hope you find this useful! Still, the credit goes to the Clojure Wiki. If you are missing something, tell me! Thank you Rich for developing this excellent piece of software. 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 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: Dependency management
On Wed, Jul 8, 2009 at 11:28 AM, Phil Hagelbergp...@hagelb.org wrote: I've been noodling on the problem of dependency management for a while now. It's definitely a pain point for projects with more than a couple dependencies. Currently our approach has been to use maven, but that involves a fair amount of arcane knowledge as well as writing a bunch of XML, which isn't a lot of fun. But there's been a community consensus that any dependency tool needs to be able to leverage all the valuable stuff out there that's currently in maven repositories. I've put together a proof-of-concept dependency manager called Corkscrew. It uses Maven under the hood as well as offering dependencies on source packages stored in git or subversion. A simple project.clj file lays out the dependencies and other project info: {:name my-sample :version 1.0 :dependencies [[tagsoup 1.2 org.ccil.cowan.tagsoup] ;; group defaults to name [rome 0.9]] :source-dependencies [[clojure-contrib r663 :svn http://clojure-contrib.googlecode.com/svn/trunk;] [enlive 95b2558943f50bb9962fe7d500ede353f1b578f0 :git git://github.com/cgrand/enlive.git]]} You can install it with: $ git clone git://github.com/technomancy/corkscrew.git $ cd corkscrew $ ./install $ cp bin/corkscrew /somewhere/on/your/path Create a project.clj file in your project root based on the one above. Then you can use corkscrew deps to set everything up for you. At that point just make sure your classpath includes target/dependency/ and you should be good to go. It's simple, but it solves the main problems that I've been having with more complicated projects. I'd love to get some opinions on it. The biggest issue right now is that it runs Maven as a subprocess rather than using the Java API in the same VM because I can't make head or tail of the Maven Java API (it uses plexus.core), but shelling out works as a proof-of-concept even if it's tacky. -Phil Thanks for bringing that up, as it's been bugging me for a some time now (and violently ejected me out of lurk mode on the list). What follows is a pretty long essay on the topic, I hope you stay with me, and take part in the debate, because I think the availability of a good buildtool/dependency manager is absolutely crucial to use Clojure in larger projects, and as such for adoption on a wider scale. I have basically the same problem as you in that Clojure is lacking a proper buildtool (i.e. one that can replace Maven). I used Maven for a long time and lived with it's strengths and weaknesses. It's far from perfect, but Maven does still give you quite a lot: * a dependency resolution and publishing model for generated artifacts * a build based on conventions (can be overridden, but Maven pushes you hard to do things in a de-facto standard way) * a defined execution model (the phases thing. Not always nice, and not always sufficient, but at least something) * a defined API to hook into with your plugins (API design is so-so, and documentation is IMHO abysmal, but ...) * a ton of reports and plugins to extend the model (not always perfect, and configuration is not nice, but they usually do what they advertise) * more? On the other hand, some things Maven are always a pain in the back: figuring out how to configure plugins, writing plugins because it's the only way to do something non-standard in Maven, and debugging/finding out what the heck is going on, if some plugin is not doing what it should do... That's the arcane knowledge part. But recently I had the need for a more flexible buildtool that would allow me to build non-standard JVM based languages in a non-standard fashion and still play nice. Case in point was that I had to marry two different dependency resolution systems (Maven style, and Jython/Python style), and then build a mix of code in Scala/Java/Jython. The experience was none too pretty with Maven. Most of the buildtools out there for JVM related stuff don't try to compete with Maven and all it's plugins and reports, but they start by replacing/wrapping Ant (and usually Ivy for dependency management). That description applies to Buildr, the Groovy Ant Builder, Gant, Grape (which is a wrapper for Ivy), SBT (Simple Build Tool - Scala), Scalr (Scala), Lancet, and probably some more that I missed. The only notable exception I could dig up was Gradle. Gradle (http://gradle.org/) turns out to be very interesting. Here are some propaganda points (not exhaustive): * Although it currently uses mainly a Groovy DSL, the Gradle core is written in Java, and there's an explicit goal on the roadmap to support DSLs written in other JVM languages on top of it as to make it an attractive choice for everybody. For Scala there's a patch in the Bugtracker to add a Scala DSL on top. Other languages I'm unaware of. * Convention based builds. They have taken
Re: Using Clojure for complex database driven applications
Check out clj-record modelled around Rails' ActiveRecord. http://elhumidor.blogspot.com/2009/01/clj-record-activerecord-for-clojure.html http://github.com/duelinmarkers/clj-record/tree/master -Suresh On Wed, Jul 8, 2009 at 3:29 PM, Baishampayan Ghoseb.gh...@ocricket.com wrote: Hello, So we are going to develop a moderately complex Database driven application in Clojure and I am looking for easy-to-manage solutions for talking to Databases. I am quite used to the way Object Relational Mappers like SQLAlchemy Django work in the Python world. We define the DB schema using simple classes and then we access and manipulate the DB using objects and their properties/methods. I would prefer a similar setup for Clojure as I would rather not deal with any kind of raw SQL. I am also a Java newbie; and I am currently looking at Hibernate (and may be Spring to make Hibernate less verbose). I would like to know how you have solved similar problems. Is Hibernate useful? Is managing a bunch of XML config files a necessary evil? Any help will be appreciated. Regards, BG -- Baishampayan Ghose b.gh...@ocricket.com oCricket.com --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
On Wed, Jul 8, 2009 at 5:14 AM, Robert Campbell rrc...@gmail.com wrote: Thanks Daniel, that makes perfect sense, especially about having random - and forgotten - code in the image. I have a lot of this during my exploration sessions. Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Trouble specifying a gen-class constructor taking an argument of the class being created
Hello, Does anyone know a straightforward way to create a constructor using gen-class that takes an argument of the same class as the class you're generating? When I try to do it I get a ClassNotFoundException, assuming I don't have a previous compiled version of the class in my compile path. Basically what I'm trying to do is: (ns my.class (:gen-class :init init :constructors {[String String] [] [some.java.Class] [] [my.class] []} :state state) (:import [stuff.goes.here])) (implementation) I could just instruct the constructor to take an Object, but that's not satisfying and forces me to branch more in -init to determine the class of the argument. On a different note, is there a capitalization convention for classes created with gen-class? Is it CamelCase since they're java classes for all intents and purposes? Or hyphen-case since we want to spread the love? Thanks, Garth --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
Looks good! You might get some additional ideas for categories from http://java.ociweb.com/mark/clojure/ClojureCategorized.html. On Wed, Jul 8, 2009 at 4:04 AM, Steve Tayonsteve.ta...@googlemail.com wrote: Hello everyone, while looking around for a modern lisp, I discovered Clojure and was instantly infected by the new possibilities to write software. Since then I watched the screencasts and read several tutorials. Finally I bought Programming Clojure by Stuart and I was impressed by his clean and well-structured writing style. There are many many great tutorials about Clojure out there, but I was interested in a summary of the available Clojure functions and macros. So I decided to hack together a Clojure cheat sheet in the style of the Latex cheat sheet by Winston Chang (http://www.stdout.org/~winston/ latex). Consequently the sheet should not contain more than two pages. At first, I though about the following arrangement: function | short description | example. Quickly I realized, that the sheet would become a book. Therefore I mostly used the categories in the Clojure Wiki on http://www.clojure.org. For example, when you are working with sequences, you can look up, which function could be used to get your things done. Most names are self-explaining and in doubt (doc function) will help you out with parameters and description. Sometimes an example for a complicated function would be useful, but in that case, you have to look up elsewhere. Sorry... You find the cheat sheet in the Clojure group file section (clojure- cheat-sheet.zip). Hope you find this useful! Still, the credit goes to the Clojure Wiki. If you are missing something, tell me! Thank you Rich for developing this excellent piece of software. Steve -- 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 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: Save current namespace like a Smalltalk image
2009/7/8 John Harrop jharrop...@gmail.com: On Wed, Jul 8, 2009 at 5:14 AM, Robert Campbell rrc...@gmail.com wrote: Thanks Daniel, that makes perfect sense, especially about having random - and forgotten - code in the image. I have a lot of this during my exploration sessions. Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. One way of doing this (although you can decide for yourself whether it's acceptable) is to run clojure inside of the Unix script command. -- Michael Wood esiot...@gmail.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Homoiconicity and printing functions
One of the things that drew me to Clojure was the fact that it's homoiconic (and my previous lisp [Scheme] was not necessarily), which means code is data, macro writing is easy etc. etc. What I'm missing is why I can't print a function. I understand that most of the functions I write use quite a few macros, and after expansion into the core forms it looks shredded...but isn't there any way for me to see a representation of this source after a function has been compiled? For instance, (def a #(+ %1 %2)) #'user/a a #user$a__3 user$a...@a141e Isn't there any way for me to get something like (deep-print a) (fn [arg1 arg2] (*built-in-+* arg1 arg2)) or whatever that anonymous lambda would actually evaluate to? Any tips greatly appreciated! Mike --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
I half-solve the what have I defined? problem with a combination of: 1) trying to always work from a file rather than entering stuff by hand at the repl 2) always working in a scrap namespace whose contents I can inspect using ns-interns and clojure.inspector/inspect-tree, like so: user= (ns scrap (:refer-clojure) (:use (clojure inspector set))) scrap= (inspect-tree (ns-interns 'scrap)) ;;shows me an empty inspector window scrap= (def x 10) scrap= (defn hello [s] (str Hello, s !)) scrap= (inspect-tree (ns-interns 'scrap)) ;;now shows me a list of what I've defined in my namespace At some point I'll improve the gui inspectors to more closely resemble (in functionality) the object inspectors from Eclipse or Idea, but this suffices for now to at least identify what things I've defined so I know to shove their definitions into a file before restarting the repl. Cheers --josh On Jul 8, 9:04 am, Robert Campbell rrc...@gmail.com wrote: Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. The only problem I see with this approach is that you leave it up to the user (me) to sort though this transcript and try to reproduce the latest version of the image. A function may be redefined many times and the only version I'd _usually_ care about is the latest. This is typically because the latest definition encompasses the latest understanding of the problem or solution. Having said that, it's better than nothing. There are certainly times when I need to backtrack to previous definitions when I've down down the wrong path. Having a transcript is better than where I'm at today. On Wed, Jul 8, 2009 at 12:00 PM, John Harropjharrop...@gmail.com wrote: On Wed, Jul 8, 2009 at 5:14 AM, Robert Campbell rrc...@gmail.com wrote: Thanks Daniel, that makes perfect sense, especially about having random - and forgotten - code in the image. I have a lot of this during my exploration sessions. Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. --~--~-~--~~~---~--~~ 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: Homoiconicity and printing functions
On Jul 8, 2009, at 9:11 AM, Mike wrote: What I'm missing is why I can't print a function. I understand that most of the functions I write use quite a few macros, and after expansion into the core forms it looks shredded...but isn't there any way for me to see a representation of this source after a function has been compiled? For instance, (def a #(+ %1 %2)) #'user/a a #user$a__3 user$a...@a141e Isn't there any way for me to get something like (deep-print a) (fn [arg1 arg2] (*built-in-+* arg1 arg2)) or whatever that anonymous lambda would actually evaluate to? Once it's compiled, it's JVM bytecode. I'm not aware of a tool that could decompile it into Clojure code, even in a low-level form. If you want to see the full expansion of a function while you still have its source, you can use mexpand-all from clojure.contrib.macro-utils: Clojure 1.1.0-alpha-SNAPSHOT user= (use 'clojure.contrib.macro-utils) nil user= (mexpand-all '#(+ %1 %2)) (fn* ([p1__1432 p2__1433] (+ p1__1432 p2__1433))) user= That output contains no macro calls. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Calling static methods on a variable holding a class
If you know the method you wish to call, do you not know the class and can thus call the static method directly? Well that was the point of the question, that is if I have to call a static method on a class we don't know in advance. I understand this capability isn't that useful and is quite rarely used, but maybe somebody will one day need it for some practical reason. ;-) My first impression is that this is probably not the best way to go about this. Java classes are not like Ruby or Python classes; you can't just call methods on them. Using eval is a hack, and probably not a good idea. Yeah, you're quite right about this. For now I'm just experimenting with some ideas on how to abstract Java libraries, nio in this case. So it's not something I really need. If you go this route, I recommend either using or learning from the functions in clojure/src/jvm/clojure/lang/Reflector.java. Its methods are not part of Clojure's official interface, so the usual caveats about using unsupported implementation private code apply, but it include many useful methods for dealing with reflection from Clojure. I'll certainly use the Reflector class, should have thought about it! I wonder if it would be a good idea to include a function for it in Clojure or in Contrib? As for the call-static macro, I now understand the error message. It was quite obvious in fact, as macros must output something that the reader can read! Thanks all! - budu --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[ANN] clj-peg 0.4
Version 0.4 brings modifications to the syntax for declaring grammars as well as suggestions about avoiding the exponential runtimes that can occur. Here is a post walking through these changeshttp://www.lithinos.com/New-syntax-and-linear-runtime-options-in-clj-peg.html . -Rich --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
To compare timings, I use this macro: (defmacro time-ms [n expr] `(let [start# (. System (nanoTime))] (dotimes [i# ~n] ~expr) (/ (double (- (. System (nanoTime)) start#)) 100.0))) (defmacro timings [n expr] (let [expr-are-not-equal (cons 'not= expr) expr-times (cons 'vector (map #(list 'time-ms n %) expr))] `(if ~expr-are-not-equal (do (println Expressions:\n) (dorun (map prn '~expr)) (println \nare NOT equal!)) (let [ts# ~expr-times max-time# (apply max ts#)] (dorun (map (fn [~'t ~'e] (printf %8.2f ms %6.1f%% %5.1fx ~'t (* 100.0 (/ ~'t max-time#)) (/ max-time# ~'t)) (prn ~'e)) ts# '~expr)) Use is: user= (timings 1e6 (+ 2 4 5) (+ 2 (+ 4 5))) 727.50 ms 100.0% 1.0x (+ 2 4 5) 353.18 ms 48.5% 2.1x (+ 2 (+ 4 5)) For our case: (let [v [1 2 3] lst '(1 2 3)] (timings 1e5 (let [[a b c] v] [a b c]) (let [a (v 0) b (v 1) c (v 2)] [a b c]) (let [a (nth v 0) b (nth v 1) c (nth v 2)] [a b c]) (let [a (first v) b (second v) c (first (rest (rest v)))] [a b c]) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] [x y z]) (let [[a b c] lst] [a b c]) ;; (let [a (lst 0) b (lst 1) c (lst 2)] [a b c]) (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] [a b c]) (let [a (first lst) b (second lst) c (first (rest (rest lst)))] [a b c]) (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] [x y z]))) And on my computer I get these numbers: 145.86 ms 64.5% 1.6x (let [[a b c] v] [a b c]) 97.37 ms 43.1% 2.3x (let [a (v 0) b (v 1) c (v 2)] [a b c]) 94.66 ms 41.9% 2.4x (let [a (nth v 0) b (nth v 1) c (nth v 2)] [a b c]) 226.15 ms 100.0% 1.0x (let [a (first v) b (second v) c (first (rest (rest v)))] [a b c]) 205.05 ms 90.7% 1.1x (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] [x y z]) 219.42 ms 97.0% 1.0x (let [[a b c] lst] [a b c]) 171.32 ms 75.8% 1.3x (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] [a b c]) 179.03 ms 79.2% 1.3x (let [a (first lst) b (second lst) c (first (rest (rest lst)))] [a b c]) 170.41 ms 75.4% 1.3x (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] [x y z]) Frantisek On Jul 8, 9:53 am, John Harrop jharrop...@gmail.com wrote: On Wed, Jul 8, 2009 at 3:42 AM, Frantisek Sodomka fsodo...@gmail.comwrote: If result is a vector v, then from these 4 cases: (let [v [1 2 3]] (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z)) using 'nth' (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) is the fastest. Is it faster than using list and manually destructuring the list? If so, that would mean that (nth v n) is faster than (get v n), which would be odd since the latter should turn into the former anyway and be inlinable by the JIT. --~--~-~--~~~---~--~~ 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: Homoiconicity and printing functions
On Wed, Jul 8, 2009 at 9:11 AM, Mike cki...@gmail.com wrote: One of the things that drew me to Clojure was the fact that it's homoiconic (and my previous lisp [Scheme] was not necessarily), which means code is data, macro writing is easy etc. etc. What I'm missing is why I can't print a function. I understand that most of the functions I write use quite a few macros, and after expansion into the core forms it looks shredded...but isn't there any way for me to see a representation of this source after a function has been compiled? If you want to see macro expansions, macroexpand and macroexpand-1 will do ya. If you want to be able to query a function for its source code later on, that's tougher. You'll need to make a macro that wraps defn and assigns a copy of the body form to a metadata tag on the function's name. --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
Mark Volkmann schrieb: Looks good! You might get some additional ideas for categories from http://java.ociweb.com/mark/clojure/ClojureCategorized.html. Thanks for the hint. I will look for missing commands and merge them into the sheet. 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 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: Homoiconicity and printing functions
On Jul 8, 10:14 am, Stephen C. Gilardi squee...@mac.com wrote: Once it's compiled, it's JVM bytecode. I'm not aware of a tool that could decompile it into Clojure code, even in a low-level form. That's what I was afraid of. How do folks interactively code with a REPL and then once things settle down dump it back out so you can make a proper module out of it? I'm using that JLine thing for command history, but I would imagine it's completely oblivious to Clojure forms so they get split (potentially, depending on how I typed it) on multiple lines. Is SLIME (slime?) a better approach to interactive development? (I.e., is it like a REPL in a buffer, and does it have hooks so you know which definition of what is actually in place currently?) I find myself doing a lot of: (use :reload-all 'some-more-stable-thing-im-working-on) (defn foobar [...] ...) ; play with stuff, oops (defn foobar [...] ...) ; fixed foobar (defn foobaz [...] ...) ; etc. (defn foobar [...] ...) ; fixed foobar again ;; now I want to take the new stuff I've experimented with in the REPL and ;; put it in some-more-stable-thing-im-working-on, but what is it? Does this make any sense? Maybe I'm not doing things right. Again, any advice on what your interactive development workflow is would be appreciated! Mike --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
anyone? Has anyone worked on Clojure box with the book examples? Last thing I tried was to load a single file (load-file c:\emacs\code \examples\introduction.clj) and what I get is the last program in that file. thanks. On Jul 8, 2:55 pm, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. [ i did my share of trying to make clojure work from cygwin and even windows command - failed to start clojure with all the libraries, had to manually create a bat file to run. Then came the indentation part, I have been typing away on one line, but is terribly messy.The biggest obstacle is indentation. I know I can edit a file and reload it, but I prefer it via the REPL] I did read about an earlier post (http://groups.google.com/group/ clojure/browse_thread/thread/0bb49e6409f43f5d/cbf20098c83215d3) but I didn't see an accepted solution to that. -dumby --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Starting REPL in vimclojure
I have setup vimclojure but am unable to start the REPL. When I give the foll. call vimclojure#Repl.New() in vim I get the foll. error: Couldn't execute Nail! java.lang.NoClassDefFoundError: Could not initialize class de.kotka.vimclojure.nails.Repl at java.lang.Class.forName0(Native Method) at java.lang.Class.forName (Class.java:169) at com.martiansoftware.nailgun.NGSession.run(Unknown Source) But, the REPL window does open up. I then hit a I to go into insert mode and type this: (+ 2 3) (ENTER key). But, nothing happens. Is it because of the error above? Thanks in advance. Additional info: vim version: 7.2.1 and vimclojure version: 2.1.1 The classpath looks like this: /home/user/clojure/clojure/clojure.jar:/home/user/clojure/clojure- contrib/clojure-contrib.jar:/home/user/clojure/vimclojure-2.1.1/build/ vimclojure.jar and I have started the NailGun Server my local.properties (for vimclojure) looks like this: clojure.jar=/home/user/clojure/clojure/clojure.jar clojure-contrib.jar=/home/user/clojure/clojure-contrib/clojure- contrib.jar nailgun-client=ng vimdir=/home/user/.vim/plugin my /etc/vim/vimrc (and /home/user/.vimrc) looks like this: syntax on filetype plugin indent on let vimclojure#NailgunClient = /home/user/clojure/vimclojure-2.1.1/ ng let g:clj_want_gorilla = 1 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie macro problems
Hi. I'm developing a simple pattern matching library for clojure but I am having trouble with macros (which I have almost zero experience with). I have a function `make-matcher` (make-matcher pattern) which returns a function that can pattern match on data and returns a map of bindings (or nil in case of a non-match). ((make-matcher '(list x y z w)) (list 1 2 3 4)) ; = {x 1 y 2 z 3 w 4} ((make-matcher '(list x y z x)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9)) ; = {x 3} I have been trying to write the following 'match' macro: (match data pattern-1 body-1 pattern-2 body-2) The macro should work like this: (match (list 1 2 3) (list 1 x) (+ x x) (list 1 x y) (+ x y)) ; = 5 I have the following macros (none of which works correctly): ; (letmap {a 1 b 2} (+ a b)) ; =(should) expand to= ; (let [a 1 b 2] (+ a b)) (defmacro letmap [dict body] `(let ~(into [] (reduce concat (eval dict))) (do ~...@body))) ; (match (list 1 2 3) ; (list 1 x) (+ x x) ; (list 1 x y) (+ x y)) ; =should expand to something like= ; (let [dict (matcher.. (list 1 2 3))] ; (if dict ; (letmap dict (+ 1 x)) ; (match (list 1 2 3) (list 1 x y) (+ x y (defmacro match [data clauses] (when clauses (let [pattern(first clauses) body (second clauses) matcher (make-matcher pattern)] `(let [dict# (~matcher ~data)] (if dict# (letmap dict# ~body) (match ~data (next (next ~clauses Any help is appreciated. Also pointers to documents and books where I can learn more about macros. Thanks. --~--~-~--~~~---~--~~ 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: Homoiconicity and printing functions
How do folks interactively code with a REPL and then once things settle down dump it back out so you can make a proper module out of it? Typically, folks don't. Use Vim, Emacs, Eclipse... any tool that provides an interactive Clojure toplevel and the ability to evaluate forms within files. You edit a file as you go, evaluating forms as they change; if you really need to, the REPL history itself is in a buffer. If you're ever in doubt as to which version is current, just \ef (in Vim) and your current file is evaluated. I'm using that JLine thing for command history, but I would imagine it's completely oblivious to Clojure forms so they get split (potentially, depending on how I typed it) on multiple lines. Indeed. Is SLIME (slime?) a better approach to interactive development? (I.e., is it like a REPL in a buffer, and does it have hooks so you know which definition of what is actually in place currently?) I don't think it has the latter, but it allows you to macroexpand, evaluate the current buffer, evaluate a form, etc. etc. --~--~-~--~~~---~--~~ 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: Newbie macro problems
This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) 2. Could you post the source to match maker? That would help my play around in a REPL 3. As for books go, get yourself a copy of Programming Clojure by Stuart Holloway Sean On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote: Hi. I'm developing a simple pattern matching library for clojure but I am having trouble with macros (which I have almost zero experience with). I have a function `make-matcher` (make-matcher pattern) which returns a function that can pattern match on data and returns a map of bindings (or nil in case of a non-match). ((make-matcher '(list x y z w)) (list 1 2 3 4)) ; = {x 1 y 2 z 3 w 4} ((make-matcher '(list x y z x)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9)) ; = {x 3} I have been trying to write the following 'match' macro: (match data pattern-1 body-1 pattern-2 body-2) The macro should work like this: (match (list 1 2 3) (list 1 x) (+ x x) (list 1 x y) (+ x y)) ; = 5 I have the following macros (none of which works correctly): ; (letmap {a 1 b 2} (+ a b)) ; =(should) expand to= ; (let [a 1 b 2] (+ a b)) (defmacro letmap [dict body] `(let ~(into [] (reduce concat (eval dict))) (do ~...@body))) ; (match (list 1 2 3) ; (list 1 x) (+ x x) ; (list 1 x y) (+ x y)) ; =should expand to something like= ; (let [dict (matcher.. (list 1 2 3))] ; (if dict ; (letmap dict (+ 1 x)) ; (match (list 1 2 3) (list 1 x y) (+ x y (defmacro match [data clauses] (when clauses (let [pattern (first clauses) body (second clauses) matcher (make-matcher pattern)] `(let [dict# (~matcher ~data)] (if dict# (letmap dict# ~body) (match ~data (next (next ~clauses Any help is appreciated. Also pointers to documents and books where I can learn more about macros. Thanks. --~--~-~--~~~---~--~~ 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: Newbie macro problems
4. Is this example from SICP? On Jul 8, 12:12 pm, Sean Devlin francoisdev...@gmail.com wrote: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) 2. Could you post the source to match maker? That would help my play around in a REPL 3. As for books go, get yourself a copy of Programming Clojure by Stuart Holloway Sean On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote: Hi. I'm developing a simple pattern matching library for clojure but I am having trouble with macros (which I have almost zero experience with). I have a function `make-matcher` (make-matcher pattern) which returns a function that can pattern match on data and returns a map of bindings (or nil in case of a non-match). ((make-matcher '(list x y z w)) (list 1 2 3 4)) ; = {x 1 y 2 z 3 w 4} ((make-matcher '(list x y z x)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9)) ; = {x 3} I have been trying to write the following 'match' macro: (match data pattern-1 body-1 pattern-2 body-2) The macro should work like this: (match (list 1 2 3) (list 1 x) (+ x x) (list 1 x y) (+ x y)) ; = 5 I have the following macros (none of which works correctly): ; (letmap {a 1 b 2} (+ a b)) ; =(should) expand to= ; (let [a 1 b 2] (+ a b)) (defmacro letmap [dict body] `(let ~(into [] (reduce concat (eval dict))) (do ~...@body))) ; (match (list 1 2 3) ; (list 1 x) (+ x x) ; (list 1 x y) (+ x y)) ; =should expand to something like= ; (let [dict (matcher.. (list 1 2 3))] ; (if dict ; (letmap dict (+ 1 x)) ; (match (list 1 2 3) (list 1 x y) (+ x y (defmacro match [data clauses] (when clauses (let [pattern (first clauses) body (second clauses) matcher (make-matcher pattern)] `(let [dict# (~matcher ~data)] (if dict# (letmap dict# ~body) (match ~data (next (next ~clauses Any help is appreciated. Also pointers to documents and books where I can learn more about macros. Thanks. --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
On Jul 8, 2009, at 5:46 AM, Robert Campbell wrote: It seems strange to me that Clojure doesn't support this concept natively Comments are part of the problem. Clojure's reader strips them out while parsing before compiling the function, so you would lose them during the first round-trip of read and print. Even a macro doesn't really solve this problem; the only possible solution is to accept comments that aren't really comments because the reader sees and preserves them, or decide that they aren't an important part of the function definition. I'm sure there are other hang-ups (closures are probably another) but this is the first one that comes to mind for me. — Daniel Lyons --~--~-~--~~~---~--~~ 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: Newbie macro problems
2009/7/8 Sean Devlin francoisdev...@gmail.com: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) Hi, s/array/vector/g Regards, -- Laurent --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
Hi, interesting, thanks for doing this ! Maybe you could add also the reader syntax for lists (), vectors [], sets #{}, maps {} or do you think they are too trivial to be in the cheat sheet ? Regards, -- Laurent 2009/7/8 Steve Tayon steve.ta...@googlemail.com: Mark Volkmann schrieb: Looks good! You might get some additional ideas for categories from http://java.ociweb.com/mark/clojure/ClojureCategorized.html. Thanks for the hint. I will look for missing commands and merge them into the sheet. 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 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: Save current namespace like a Smalltalk image
Isn't this why you would use a doc string, and not a comment? On Jul 8, 12:14 pm, Daniel Lyons fus...@storytotell.org wrote: On Jul 8, 2009, at 5:46 AM, Robert Campbell wrote: It seems strange to me that Clojure doesn't support this concept natively Comments are part of the problem. Clojure's reader strips them out while parsing before compiling the function, so you would lose them during the first round-trip of read and print. Even a macro doesn't really solve this problem; the only possible solution is to accept comments that aren't really comments because the reader sees and preserves them, or decide that they aren't an important part of the function definition. I'm sure there are other hang-ups (closures are probably another) but this is the first one that comes to mind for me. — Daniel Lyons --~--~-~--~~~---~--~~ 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: Is this unquote dangerous?
On Jul 7, 5:02 am, Mike cki...@gmail.com wrote: (not sure where my reply to Chouser et al. went, but basically I said that I was writing a macro and I might be overdoing it. I was right!) Here's what I was trying to accomplish, but in functions, not macros: (defn slice Returns a lazy sequence composed of every nth item of coll, starting from offset. [n offset coll] (if (= offset 0) (take-nth n coll) (take-nth n (drop offset coll [snip] Your slice function looks similar to the built-in partition: (defn slice [n offset coll] (apply concat (partition 1 n (drop offset coll --~--~-~--~~~---~--~~ 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: Newbie macro problems
Laurent, I don't quite understand your point. Could you please explain it a little more? Thanks On Jul 8, 12:16 pm, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/7/8 Sean Devlin francoisdev...@gmail.com: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) Hi, s/array/vector/g Regards, -- Laurent --~--~-~--~~~---~--~~ 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: Dependency management
Daniel dan.in.a.bot...@gmail.com writes: I would very much like to see that people don't suffer the NIH syndrome everywhere. Usually people forget that every alternative technology implemented has an associated cost that everyone looking for a solution has to pay, because I have to consciously discard the tool as insufficient, and that means I have to acquire enough knowledge about each tool to make an informed decision (the paradox of choice). I cannot even imagine how much time has been wasted by halfbaked (and partially or fully abandoned) projects. Interesting. If you think this is promising, let's see some code. Like I said, corkscrew is not much more than a proof of concept. It's only 210 lines of code; I haven't invested lots of effort in it. If you think something based on Gradle has a better chance of taking off and meeting people's needs, I'd love to see that in action. For my own needs, I care primarily about dependency management, which as far as I can tell is the one thing that Maven does well. (I had never used Maven before working with Clojure, so I make no claims towards knowing what I'm talking about wrt Java build systems.) The actual compilation phase is generally trivial for the projects I've worked on once you've got your deps in place, so that's what I decided to tackle first with corkscrew. In my mind the place it makes sense to share infrastructure with other JVM languages is in the repository format, so I'm unlikely to invest much effort in Gradle unless there's community consensus what it offers is really advantageous. (I know better than to write code that solves problems I don't personally have.) But if Gradle is shown to be a solid tool that gains traction, I'd love to help hack on it. I just don't want to ever have to download a jar and add it to my classpath manually ever again, and the less XML I have to churn out, the better. -Phil --~--~-~--~~~---~--~~ 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: Starting REPL in vimclojure
Hi, Am 08.07.2009 um 16:56 schrieb Bart J: I have setup vimclojure but am unable to start the REPL. When I give the foll. call vimclojure#Repl.New() in vim I get the foll. error: Couldn't execute Nail! java.lang.NoClassDefFoundError: Could not initialize class de.kotka.vimclojure.nails.Repl at java.lang.Class.forName0(Native Method) at java.lang.Class.forName (Class.java:169) at com.martiansoftware.nailgun.NGSession.run(Unknown Source) Your VC jar is broken. It contains the nailgun part, but not the VC nails. Please re-built the jar. Look out for compilation problems! Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Homoiconicity and printing functions
Mike cki...@gmail.com writes: I'm using that JLine thing for command history, but I would imagine it's completely oblivious to Clojure forms so they get split (potentially, depending on how I typed it) on multiple lines. It's easy to get in a state where you're not sure how to reproduce it if you enter a lot of defns at the REPL that didn't come from a file. That's why editor integration is important. Is SLIME (slime?) a better approach to interactive development? (I.e., is it like a REPL in a buffer, and does it have hooks so you know which definition of what is actually in place currently?) Yeah, SLIME can do that. For any var (unless it was entered at the REPL or via eval), you can jump to the file location that contains its definition. It's also easy to send a whole file to the REPL, which makes it easy to ensure that the current instance is consistent with what's on disk. -Phil --~--~-~--~~~---~--~~ 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: Newbie macro problems
Good point. I'll be careful to use the term vector in the future, and array for java interop only. On Jul 8, 12:30 pm, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/7/8 Sean Devlin francoisdev...@gmail.com: Laurent, I don't quite understand your point. Could you please explain it a little more? Oh, I wanted to be quick. I think using the term array instead of vector (which is the real term used for datastructure created by a [:a :b :c :d] form) may be confusing (one could overlook and understand java array). see:http://clojure.org/data_structures#toc15 and from (http://clojure.org/reader): Vectors Vectors are zero or more forms enclosed in square brackets: [1 2 3] Regards, -- Laurent Thanks On Jul 8, 12:16 pm, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/7/8 Sean Devlin francoisdev...@gmail.com: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) Hi, s/array/vector/g Regards, -- Laurent --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Robert Campbell rrc...@gmail.com writes: The main reason this is an issue for me is during development I sometimes find I need another library added to my classpath. Right now the only way I know how to modify the classpath in Emacs is to change the .emacs file with an add-to-list 'swank-clojure-extra-classpaths and reboot. I think my looking for an image solution might be a cop-out itself; I need to learn Emacs better so I can figure out how to modify the classpath without rebooting. Unfortunately this is impossible due to the way the classloaders in the JVM work; you can't modify your classpath at runtime and have it work consistently. The solution I've settled on is to have a static classpath; no matter what the project is, my classpath is always the same: src/:target/dependency/:target/classes/:test/ When you need to add a new library, instead of putting the jar on the classpath, just unpack the jar in the target/dependency directory. Then you can access it without restarting the JVM. -Phil --~--~-~--~~~---~--~~ 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: Newbie macro problems
2009/7/8 Sean Devlin francoisdev...@gmail.com: Laurent, I don't quite understand your point. Could you please explain it a little more? Oh, I wanted to be quick. I think using the term array instead of vector (which is the real term used for datastructure created by a [:a :b :c :d] form) may be confusing (one could overlook and understand java array). see: http://clojure.org/data_structures#toc15 and from ( http://clojure.org/reader ): Vectors Vectors are zero or more forms enclosed in square brackets: [1 2 3] Regards, -- Laurent Thanks On Jul 8, 12:16 pm, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/7/8 Sean Devlin francoisdev...@gmail.com: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) Hi, s/array/vector/g Regards, -- Laurent --~--~-~--~~~---~--~~ 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: Homoiconicity and printing functions
Hi, I'd like to second the suggestion of Richard and Daniel (in the other thread): use a file. It solves almost all problems with immediate effect. Here is my workflow for your example. I added some annotations. (as a note: I use VimClojure for development) Am 08.07.2009 um 16:39 schrieb Mike: (use :reload-all 'some-more-stable-thing-im-working-on) In REPL. (defn foobar [...] ...) In file. Send expression to the REPL via \et. ; play with stuff, oops In REPL. (defn foobar [...] ...) ; fixed foobar In file. Send expression to the REPL. ; play with stuff, oops In REPL. (Repeat as necessary with: (defn foobaz [...] ...) ; etc. (defn foobar [...] ...) ; fixed foobar again ) ;; now I want to take the new stuff I've experimented with in the REPL and ;; put it in some-more-stable-thing-im-working-on, but what is it? Add suitable (ns) clause a the top of the file and put it into the right directory structure... This solves almost all problems: * you always have the latest version available * if unsure, just load the whole file to get a clean state * you can comment your functions easily * you have them syntax highlighted * you have them properly indented * you don't clutter your REPL history with multiline function definitions * you can easily restart with a fresh REPL (just load the file) * you can easily move the stuff to a proper namespace * whether to paste a REPL history or the file in some etherpaste thingy should not make a difference... In the REPL just play with your functions. Hope this helps. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Save current namespace like a Smalltalk image
On Jul 8, 2009, at 10:22 AM, Sean Devlin wrote: Isn't this why you would use a doc string, and not a comment? Docstrings aren't the only comments in my code. :) — Daniel Lyons --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
Great idea, maybe you should talk to dzone.com about turning this into a refcard. On Jul 8, 2009, at 5:04 AM, Steve Tayon steve.ta...@googlemail.com wrote: Hello everyone, while looking around for a modern lisp, I discovered Clojure and was instantly infected by the new possibilities to write software. Since then I watched the screencasts and read several tutorials. Finally I bought Programming Clojure by Stuart and I was impressed by his clean and well-structured writing style. There are many many great tutorials about Clojure out there, but I was interested in a summary of the available Clojure functions and macros. So I decided to hack together a Clojure cheat sheet in the style of the Latex cheat sheet by Winston Chang (http://www.stdout.org/ ~winston/ latex). Consequently the sheet should not contain more than two pages. At first, I though about the following arrangement: function | short description | example. Quickly I realized, that the sheet would become a book. Therefore I mostly used the categories in the Clojure Wiki on http://www.clojure.org. For example, when you are working with sequences, you can look up, which function could be used to get your things done. Most names are self-explaining and in doubt (doc function) will help you out with parameters and description. Sometimes an example for a complicated function would be useful, but in that case, you have to look up elsewhere. Sorry... You find the cheat sheet in the Clojure group file section (clojure- cheat-sheet.zip). Hope you find this useful! Still, the credit goes to the Clojure Wiki. If you are missing something, tell me! Thank you Rich for developing this excellent piece of software. 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 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: Save current namespace like a Smalltalk image
what's the problem with adding urls to the current ClassLoader ? i've seen remarks to the effect that it doesn't work well, but i don't understand why... c On 8 Jul 2009, at 17:37, Phil Hagelberg wrote: Robert Campbell rrc...@gmail.com writes: The main reason this is an issue for me is during development I sometimes find I need another library added to my classpath. Right now the only way I know how to modify the classpath in Emacs is to change the .emacs file with an add-to-list 'swank-clojure-extra-classpaths and reboot. I think my looking for an image solution might be a cop-out itself; I need to learn Emacs better so I can figure out how to modify the classpath without rebooting. Unfortunately this is impossible due to the way the classloaders in the JVM work; you can't modify your classpath at runtime and have it work consistently. The solution I've settled on is to have a static classpath; no matter what the project is, my classpath is always the same: src/:target/dependency/:target/classes/:test/ When you need to add a new library, instead of putting the jar on the classpath, just unpack the jar in the target/dependency directory. Then you can access it without restarting the JVM. -Phil --~--~-~--~~~---~--~~ 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: Using Clojure for complex database driven applications
Lau, one of the co-developer sad he was working on pgsql, I haven't tried it with pgsql. I'm sure he'll jump in here. :) As for maturity, apprently 1.0 release is near. I only tried some limited queries so far. You should stress test it for your project. On 7/8/09, Baishampayan Ghose b.gh...@ocricket.com wrote: Wilson MacGyver wrote: Take a look at ClojureQL http://github.com/Lau-of-DK/clojureql/tree/master It's not a ORM system like SQLAlchemy/Django ORM in that it won't manage the table schema for you. There is also clj-record. http://github.com/duelinmarkers/clj-record/tree/master which is inspired by rail's ActiveRecord. How mature are they? Do they work well with PostgreSQL? Apparently, ClojureQL doesn't. Regards, BG -- Baishampayan Ghose b.gh...@ocricket.com oCricket.com -- Sent from my mobile device Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Unfortunately this is impossible due to the way the classloaders in the JVM work; you can't modify your classpath at runtime and have it work consistently. Doesn't this seem a little crazy though? My day job is Java dev in Eclipse and a little IntelliJ and both IDEs allow you to modify classpath at any time. It seems like it would be a basic requirement for any IDE. Think of how often you do this. If I had to reboot Eclipse every time I'd go crazy. Then throw in the lack of image support and it becomes a real obstacle. Does anyone know exactly when the JVM is booted for the REPL? Is it from swank or clojure-mode or one of these systems? Couldn't there be a way to reboot this subsystem instead of all Emacs? Maybe from the command line you could execute the (add-to-list 'swank-clojure-extra-classpaths /whatever) then reboot the subsystem which invokes the JVM? Or modify the .emacs file and just reboot the subsystem? It's tough because I'm completely new to Emacs and I'm not clear on how all the pieces fit together yet. On Wed, Jul 8, 2009 at 7:14 PM, mccraigmccraigmccraigmccr...@googlemail.com wrote: what's the problem with adding urls to the current ClassLoader ? i've seen remarks to the effect that it doesn't work well, but i don't understand why... c On 8 Jul 2009, at 17:37, Phil Hagelberg wrote: Robert Campbell rrc...@gmail.com writes: The main reason this is an issue for me is during development I sometimes find I need another library added to my classpath. Right now the only way I know how to modify the classpath in Emacs is to change the .emacs file with an add-to-list 'swank-clojure-extra-classpaths and reboot. I think my looking for an image solution might be a cop-out itself; I need to learn Emacs better so I can figure out how to modify the classpath without rebooting. Unfortunately this is impossible due to the way the classloaders in the JVM work; you can't modify your classpath at runtime and have it work consistently. The solution I've settled on is to have a static classpath; no matter what the project is, my classpath is always the same: src/:target/dependency/:target/classes/:test/ When you need to add a new library, instead of putting the jar on the classpath, just unpack the jar in the target/dependency directory. Then you can access it without restarting the JVM. -Phil --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
That looks like what I'm after. When I run a test, however, it doesn't behave properly: You'll want to either eval the expression, or apply the first item in the list to the rest: user= (eval (list + 1 2)) 3 user= (let [form (list + 1 2)] (when (not (empty? form)) (apply (first form) (rest form 3 --~--~-~--~~~---~--~~ 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: Using Clojure for complex database driven applications
Hi, Am 08.07.2009 um 12:10 schrieb Baishampayan Ghose: How mature are they? Do they work well with PostgreSQL? Apparently, ClojureQL doesn't. ClojureQL is not very mature at the moment. Eg. the join syntax will change soon. Other parts need clean up. Basic things are still missing. We cannot test all database backends. And there are as much special cases as there are backends. So if anyone wants to lend a hand in making CQL fit for a backend, we are happy to accept any support. Examples are already there for MySQL and Derby. Eg. FULL JOIN is emulated, since both backends don't support it. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Trouble specifying a gen-class constructor taking an argument of the class being created
Does anyone know a straightforward way to create a constructor using gen-class that takes an argument of the same class as the class you're generating? I've actually hit a related problem: a generated class cannot have type annotations for itself (because, as you've noticed, the class doesn't exist yet), and thus ends up using reflection when calling its own inherited methods. I end up annotating the 'this' argument with the superclass name, but of course that's not strictly correct. On a different note, is there a capitalization convention for classes created with gen-class? Is it CamelCase since they're java classes for all intents and purposes? Or hyphen-case since we want to spread the love? I use PascalCase. (camelCase is where there's a hump in the middle.) ;) --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Robert Campbell rrc...@gmail.com writes: Doesn't this seem a little crazy though? My day job is Java dev in Eclipse and a little IntelliJ and both IDEs allow you to modify classpath at any time. It seems like it would be a basic requirement for any IDE. Think of how often you do this. If I had to reboot Eclipse every time I'd go crazy. Then throw in the lack of image support and it becomes a real obstacle. Oh, sorry; sounds like I was unclear. You don't have to restart Emacs, just the JVM subprocess. M-x slime-restart-inferior-lisp You don't run into this problem with Java dev in Eclipse because Java doesn't have a REPL. I agree that it sucks though. Unpacking your dependencies all in one place is a lot nicer anyway; no restarts required. -Phil --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. For the record, this is usually termed dribbling in the Lisp world. It's very handy for debugging customer interaction -- just tell them to turn on dribble, and have them send you the file rather than copying and pasting: http://www.franz.com/support/documentation/8.1/doc/introduction.htm#reporting-bugs-1 --~--~-~--~~~---~--~~ 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: Newbie macro problems
1. Ok, I'll consider that. 2. Yes, I'll post a link when I have uploaded the code somewhere. 3. It has not yet arrived 4. No. I have two sources of inspiration. Pattern matching in PLT Scheme and this link: http://groups.csail.mit.edu/mac/users/gjs/6.945/psets/ps05/ps.txt (which is almost SICP as it is written by Sussman) On Wed, Jul 8, 2009 at 7:15 PM, Sean Devlinfrancoisdev...@gmail.com wrote: 4. Is this example from SICP? On Jul 8, 12:12 pm, Sean Devlin francoisdev...@gmail.com wrote: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) 2. Could you post the source to match maker? That would help my play around in a REPL 3. As for books go, get yourself a copy of Programming Clojure by Stuart Holloway Sean On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote: Hi. I'm developing a simple pattern matching library for clojure but I am having trouble with macros (which I have almost zero experience with). I have a function `make-matcher` (make-matcher pattern) which returns a function that can pattern match on data and returns a map of bindings (or nil in case of a non-match). ((make-matcher '(list x y z w)) (list 1 2 3 4)) ; = {x 1 y 2 z 3 w 4} ((make-matcher '(list x y z x)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9)) ; = {x 3} I have been trying to write the following 'match' macro: (match data pattern-1 body-1 pattern-2 body-2) The macro should work like this: (match (list 1 2 3) (list 1 x) (+ x x) (list 1 x y) (+ x y)) ; = 5 I have the following macros (none of which works correctly): ; (letmap {a 1 b 2} (+ a b)) ; =(should) expand to= ; (let [a 1 b 2] (+ a b)) (defmacro letmap [dict body] `(let ~(into [] (reduce concat (eval dict))) (do ~...@body))) ; (match (list 1 2 3) ; (list 1 x) (+ x x) ; (list 1 x y) (+ x y)) ; =should expand to something like= ; (let [dict (matcher.. (list 1 2 3))] ; (if dict ; (letmap dict (+ 1 x)) ; (match (list 1 2 3) (list 1 x y) (+ x y (defmacro match [data clauses] (when clauses (let [pattern (first clauses) body (second clauses) matcher (make-matcher pattern)] `(let [dict# (~matcher ~data)] (if dict# (letmap dict# ~body) (match ~data (next (next ~clauses Any help is appreciated. Also pointers to documents and books where I can learn more about macros. Thanks. --~--~-~--~~~---~--~~ 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: Newbie macro problems
2. http://gist.github.com/142939 On Wed, Jul 8, 2009 at 7:19 PM, Jonas Enlundjonas.enl...@gmail.com wrote: 1. Ok, I'll consider that. 2. Yes, I'll post a link when I have uploaded the code somewhere. 3. It has not yet arrived 4. No. I have two sources of inspiration. Pattern matching in PLT Scheme and this link: http://groups.csail.mit.edu/mac/users/gjs/6.945/psets/ps05/ps.txt (which is almost SICP as it is written by Sussman) On Wed, Jul 8, 2009 at 7:15 PM, Sean Devlinfrancoisdev...@gmail.com wrote: 4. Is this example from SICP? On Jul 8, 12:12 pm, Sean Devlin francoisdev...@gmail.com wrote: This seems like a good use for a macro. A couple of thoughts: 1. Use arrays instead of lists In clojure, it is best practice to use arrays for data. So, your macro call should look like this. (match [1 2 3] [1 x] (+ x x) [1 x y] (+ x y)) 2. Could you post the source to match maker? That would help my play around in a REPL 3. As for books go, get yourself a copy of Programming Clojure by Stuart Holloway Sean On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote: Hi. I'm developing a simple pattern matching library for clojure but I am having trouble with macros (which I have almost zero experience with). I have a function `make-matcher` (make-matcher pattern) which returns a function that can pattern match on data and returns a map of bindings (or nil in case of a non-match). ((make-matcher '(list x y z w)) (list 1 2 3 4)) ; = {x 1 y 2 z 3 w 4} ((make-matcher '(list x y z x)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4)) ; = nil ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9)) ; = {x 3} I have been trying to write the following 'match' macro: (match data pattern-1 body-1 pattern-2 body-2) The macro should work like this: (match (list 1 2 3) (list 1 x) (+ x x) (list 1 x y) (+ x y)) ; = 5 I have the following macros (none of which works correctly): ; (letmap {a 1 b 2} (+ a b)) ; =(should) expand to= ; (let [a 1 b 2] (+ a b)) (defmacro letmap [dict body] `(let ~(into [] (reduce concat (eval dict))) (do ~...@body))) ; (match (list 1 2 3) ; (list 1 x) (+ x x) ; (list 1 x y) (+ x y)) ; =should expand to something like= ; (let [dict (matcher.. (list 1 2 3))] ; (if dict ; (letmap dict (+ 1 x)) ; (match (list 1 2 3) (list 1 x y) (+ x y (defmacro match [data clauses] (when clauses (let [pattern (first clauses) body (second clauses) matcher (make-matcher pattern)] `(let [dict# (~matcher ~data)] (if dict# (letmap dict# ~body) (match ~data (next (next ~clauses Any help is appreciated. Also pointers to documents and books where I can learn more about macros. Thanks. --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
Interesting. How are these timings affected if you add in the time taken to pack the list or vector in the first place, though? I have the feeling it may be slightly cheaper to unpack a vector, but noticeably cheaper to pack a list... --~--~-~--~~~---~--~~ 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: Calling static methods on a variable holding a class
Lets say you want to call static method foo of a class, but you don't know which class -- you want this to be specified at runtime in a parameter. Something like this: (defn map-foo [cls coll] (map cls/foo coll)) ; doesn't work As mentioned by others, one approach is to use reflection, either Java's API or Clojure's (undocumented, may-change-without-warning) wrapper: (defn map-foo [cls coll] (map #(clojure.lang.Reflector/invokeStaticMethod cls foo (to-array [%])) coll)) (map-foo MyClass [1 2 3 4]) This works, but if you're allowed to adjust the requirements a bit, a better solution is possible. What if your user called: (map-foo #(MyClass/foo %) [1 2 3 4]) This can be done without any runtime reflection at all, which can greatly boost the runtime speed. Also, it's more flexible: I *told* you to name your method foo but I guess I should have been more explicit. Oh well, no matter: (map-foo #(YourClass/Foo %) [1 2 3 4]) Or if your user is using Clojure rather than Java, they don't even have to use a class: (map-foo #(her-do-foo-thing %) [1 2 3 4]) or just: (map-foo her-do-foo-thing [1 2 3 4]) Best of all implementing map-foo is simpler: (defn map-foo [f coll] (map f coll)) Which in this trivial example means you can just use 'map' instead of 'map-foo'. But even in a less trivial example you may find this approach more workable all around. Wow, that was a great answer, a thousand thanks Now if you were going to do more than one thing on the class (call static methods foo, bar, and baz, for example) things get more complicated. Yeah, that was one of constraint for the problem I was trying to solve, I should have mentioned it. - budu --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
That's it, that's exactly what I needed to complete this example. I'm pretty pumped because you guys have shown me a way to do it without macros and without manually managing a quoted tree structure. If it's okay, could somebody explain the difference between what's happening here: user (def my-func (list + 1 2)) #'user/my-func user (my-func) ; Evaluation aborted. and here: user (def my-func (list + 1 2)) #'user/my-func user (eval my-func) 3 I don't really understand how: user(my-func) is NOT eval on my-func in the REPL. My understanding is the first item in the list is treated as a function, with the rest of the list passed as arguments. Wouldn't the REPL just be calling eval internally on everything you type in? On Wed, Jul 8, 2009 at 7:22 PM, Richard Newmanholyg...@gmail.com wrote: That looks like what I'm after. When I run a test, however, it doesn't behave properly: You'll want to either eval the expression, or apply the first item in the list to the rest: user= (eval (list + 1 2)) 3 user= (let [form (list + 1 2)] (when (not (empty? form)) (apply (first form) (rest form 3 --~--~-~--~~~---~--~~ 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: Trouble specifying a gen-class constructor taking an argument of the class being created
On Wed, Jul 8, 2009 at 7:57 AM, Garth Sheldon-Coulsong...@mit.edu wrote: Hello, Does anyone know a straightforward way to create a constructor using gen-class that takes an argument of the same class as the class you're generating? I think what you're describing is: http://www.assembla.com/spaces/clojure/tickets/84 --Chouser --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
On Wed, Jul 8, 2009 at 2:55 AM, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... C-x C-f ~/.emacs. More info in the Customization section of the README.rtf that installs with Clojure Box. 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath. Shawn --~--~-~--~~~---~--~~ 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: Questions / guidelines for adopting Clojure
On Jul 7, 7:08 am, Roman Roelofsen roman.roelof...@googlemail.com wrote: Hi all! I've been playing around with Clojure in the last couple of days. Very interesting! However, I have never used a non-OO, lispy, pure functional language before and several questions popped up while snip Clojure is /not/ a pure functional programming language. That's the first step in recovery. --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
Phil - got it. It wouldn't be hard at all to write a script to monitor a directory, and any jar you throw in there gets exploded to the classpath dir like you use. That would make it pretty painless. For the record, this is usually termed dribbling in the Lisp world. It's very handy for debugging customer interaction -- just tell them to turn on dribble, and have them send you the file rather than copying and pasting: I hate to go completely off topic, but could you explain what advices are in Lisp? When I was reading a post by Steve Yegge he wrote As far as I know, Lisp had it first, and it's called advice in Lisp. Advice is a mini-framework that provides before, around, and after hooks by which you can programmatically modify the behavior of some action or function call in the system. http://steve-yegge.blogspot.com/2007/01/pinocchio-problem.html Searching turns up some pretty thin results, maybe the better one being details on Emacs Lisp advices: http://www.delorie.com/gnu/docs/elisp-manual-21/elisp_212.html Does Clojure support something like this? I didn't come across it in Stuart's book, website, etc. and AOP certainly helps manage complexity in Java On Wed, Jul 8, 2009 at 7:34 PM, Richard Newmanholyg...@gmail.com wrote: Perhaps instead of saving an image, it should be able to save a transcript of the REPL inputs? Then you could rescue code from this, or find any cruft your image had become dependent on, or whatever. For the record, this is usually termed dribbling in the Lisp world. It's very handy for debugging customer interaction -- just tell them to turn on dribble, and have them send you the file rather than copying and pasting: http://www.franz.com/support/documentation/8.1/doc/introduction.htm#reporting-bugs-1 --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
1. Here is my .emacs I use for Clojure Box to load the Jars and add the proper paths to your classpath: (setq swank-clojure-extra-classpaths '()) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure/clojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/compojure/deps/jetty-6.1.16.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/technomancy-clojure-http-client/src) etc... just add directories and jars as needed 2. Your .emacs file would be here: C:\Documents and Settings\${your username}\Application Data 3. I don't know about this one, but I had problems setting my home directory. Even though I did it, it was still looking in C:\Documents and Settings\${your username}\Application Data. Files there would load fine. On Wed, Jul 8, 2009 at 8:02 PM, Shawn Hoovershawn.hoo...@gmail.com wrote: On Wed, Jul 8, 2009 at 2:55 AM, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... C-x C-f ~/.emacs. More info in the Customization section of the README.rtf that installs with Clojure Box. 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath. Shawn --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
Oh, here's an example snippet I just saw from Daniel Lyon on another thread (note how it cleverly grabs all the jars from the ~/.clojure directory--you could add another one of these for another directory of jars): (setq swank-clojure-extra-classpaths (cons /Users/fusion/Projects/Languages/Clojure/classes (cons /Users/fusion/Projects/Languages/Clojure (directory-files ~/.clojure t \.jar$ (eval-after-load 'clojure-mode '(clojure-slime-config)) (setq swank-clojure-extra-vm-args '(-Dclojure.compile.path=/Users/ fusion/Projects/Languages/Clojure/classes)) On Wed, Jul 8, 2009 at 2:02 PM, Shawn Hoover shawn.hoo...@gmail.com wrote: On Wed, Jul 8, 2009 at 2:55 AM, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... C-x C-f ~/.emacs. More info in the Customization section of the README.rtf that installs with Clojure Box. 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath. Shawn --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
I hate to go completely off topic, but could you explain what advices are in Lisp? When I was reading a post by Steve Yegge he wrote CLOS (the Common Lisp Object System) has before, around, and after methods. Advice is similar, and certainly informed the CL standard. So far as I understand it, advice (in its various historical forms) provides a way to intercept the call to a function to modify arguments or otherwise advise the function about what to do. The function continues to do the heavy lifting, but is unaware of the advice. CLOS around methods can do the same thing, with two differences: * Advice is -- I think -- intended to be narrower in scope (you don't put big functionality in advice: you add individual features). Emacs doesn't follow this, of course :) * Advice is more modular -- around/before/after methods in CLOS are run in a defined order, each controlling the invocation of the next around method; multiple pieces of advice can be toggled on or off. You'd do things like turn on tracing/logging/profiling using advice. Interesting reading: http://p-cos.blogspot.com/2007/12/origin-of-advice.html Does Clojure support something like this? I didn't come across it in Stuart's book, website, etc. and AOP certainly helps manage complexity in Java. IME AOP in OO languages usually helps because they lack higher-order functions, first-order functions, and other linguistic features. It's much easier to define global triggers in Lisps: just have some global list of function objects that you can call, call a method and allow other people to define their own arounds, etc. You can implement something like method combinations in Clojure, but it's not built in. People have worked on CLOS-style object systems in Clojure: http://code.google.com/p/explorersguild/wiki/XGModelAndGF HTH, -R --~--~-~--~~~---~--~~ 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: Questions / guidelines for adopting Clojure
On Jul 7, 4:08 am, Roman Roelofsen roman.roelof...@googlemail.com wrote: * Parametrization of function groups * Lets say I have a bunch of functions that provide database operations (read, write, delete, ...). They all share information about the database the operate on. In an OO language, I would define these methods in the same class and an instance variable would define the database. The advantage is, that the caller side does not need to be aware of the database name. I can create an instance somewhere and pass around the object. For this particular case i just create a simple macro with-db, that behind the scenes passes a premade db connection info into with- connection macro. So the actiual usage looks very simple and clean: (with-db (sql-val [select name from author where id = ? 123])) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
zip of docs?
is there an archive of e.g. http://clojure.org/Reference i can download for offline work? i haven't found it yet if there is :-) thanks! --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
So far it seems that vectors win in Clojure: (timings 3e5 (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c))) = 680.63 ms 83.6% 1.2x (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) 813.79 ms 100.0% 1.0x (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c)) Frantisek On Jul 8, 7:29 pm, John Harrop jharrop...@gmail.com wrote: Interesting. How are these timings affected if you add in the time taken to pack the list or vector in the first place, though? I have the feeling it may be slightly cheaper to unpack a vector, but noticeably cheaper to pack a list... --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
Laurent PETIT schrieb: Hi, interesting, thanks for doing this ! Maybe you could add also the reader syntax for lists (), vectors [], sets #{}, maps {} or do you think they are too trivial to be in the cheat sheet ? Although the initialisation of lists, vectors etc. is a reader task, I will put them into their relevant data structures section, if there are no complaints. Thanks for pointing this out! On 8 Jul., 19:03, Wilson MacGyver wmacgy...@gmail.com wrote: Great idea, maybe you should talk to dzone.com about turning this into a refcard. You don't like the design, huh? I find it a little bit annoying, that I have to register to get their cheat sheets. So it is not as fast accessible as I would wish for. - Since I don't want to spam the Files section in this clojure group with one single file for every new revision. Is there a way to overwrite or remove files? --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
Thanks Shawn, Robert. From Robert's post, I am bit confused here. I also read that .emacs is in %appdata% folder (vista), but all I see is .emacs.d folder (which I guess is for the emacs server). I tried creating one C-x C-f ~/.emacs - under my home-directory (C:\emacs). Should i just create a .emacs under %appdata%/.emacs.d OR right under %appdata%? thx again. On Jul 9, 2:13 am, Robert Campbell rrc...@gmail.com wrote: 1. Here is my .emacs I use for Clojure Box to load the Jars and add the proper paths to your classpath: (setq swank-clojure-extra-classpaths '()) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure/clojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/compojure/deps/jetty-6.1.16.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/technomancy-clojure-http-client/src) etc... just add directories and jars as needed 2. Your .emacs file would be here: C:\Documents and Settings\${your username}\Application Data 3. I don't know about this one, but I had problems setting my home directory. Even though I did it, it was still looking in C:\Documents and Settings\${your username}\Application Data. Files there would load fine. On Wed, Jul 8, 2009 at 8:02 PM, Shawn Hoovershawn.hoo...@gmail.com wrote: On Wed, Jul 8, 2009 at 2:55 AM, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... C-x C-f ~/.emacs. More info in the Customization section of the README.rtf that installs with Clojure Box. 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath. Shawn --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
Robert? Is that all you have in your .emacs? I am looking to create one from scratch. I noticed that you have clojure / clojure-contrib jars in your .emacs, but what about slime/swank settings? won't they be overridden by Clojure Box -settings or other way - .emacs loading without slime/ swank? (taking a blind guess) On Jul 9, 2:13 am, Robert Campbell rrc...@gmail.com wrote: 1. Here is my .emacs I use for Clojure Box to load the Jars and add the proper paths to your classpath: (setq swank-clojure-extra-classpaths '()) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure/clojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/compojure/deps/jetty-6.1.16.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/technomancy-clojure-http-client/src) etc... just add directories and jars as needed 2. Your .emacs file would be here: C:\Documents and Settings\${your username}\Application Data 3. I don't know about this one, but I had problems setting my home directory. Even though I did it, it was still looking in C:\Documents and Settings\${your username}\Application Data. Files there would load fine. On Wed, Jul 8, 2009 at 8:02 PM, Shawn Hoovershawn.hoo...@gmail.com wrote: On Wed, Jul 8, 2009 at 2:55 AM, dumb me dumb...@gmail.com wrote: Hi All, I am a dumb around here. my first post among many to come :) I setup clojurebox to work thru the book. I am a newbie to emacs and to clojure. I don't mind the learning curve to emacs. I am completely blank about configuring Clojurebox. Here's what I want to do: 1) load all the code-examples and the related jar-files of the book - when I load ClojureBox. This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu. 2) Where do I find the .emacs for Clojure Box? As I understand that I will have to modify this file to include the libraries/folder-path. I don't see one... C-x C-f ~/.emacs. More info in the Customization section of the README.rtf that installs with Clojure Box. 3) I have been trying to do (load-file code.examples.introduction.clj) [my home directory being c:\emacs and the code folder inside the emacs folder.] and I always get the File-not-found exception. Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath. Shawn --~--~-~--~~~---~--~~ 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: zip of docs?
It looks like anyone with Organizer rights on Clojure's wikispaces wiki should be able to export an HTML or WikiText backup zip file. Justin On Wed, Jul 8, 2009 at 3:23 PM, Raoul Duke rao...@gmail.com wrote: is there an archive of e.g. http://clojure.org/Reference i can download for offline work? i haven't found it yet if there is :-) thanks! --~--~-~--~~~---~--~~ 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: Save current namespace like a Smalltalk image
On Wed, Jul 8, 2009 at 11:37 PM, Phil Hagelbergp...@hagelb.org wrote: Robert Campbell rrc...@gmail.com writes: The main reason this is an issue for me is during development I sometimes find I need another library added to my classpath. Right now the only way I know how to modify the classpath in Emacs is to change the .emacs file with an add-to-list 'swank-clojure-extra-classpaths and reboot. I think my looking for an image solution might be a cop-out itself; I need to learn Emacs better so I can figure out how to modify the classpath without rebooting. Unfortunately this is impossible due to the way the classloaders in the JVM work; you can't modify your classpath at runtime and have it work consistently. The solution I've settled on is to have a static classpath; no matter what the project is, my classpath is always the same: src/:target/dependency/:target/classes/:test/ When you need to add a new library, instead of putting the jar on the classpath, just unpack the jar in the target/dependency directory. Then you can access it without restarting the JVM. /snip You don't run into this problem with Java dev in Eclipse because Java doesn't have a REPL. I agree that it sucks though. Unpacking your dependencies all in one place is a lot nicer anyway; no restarts required. Uhm, that's not exactly true. The classpath is what you give your VM as initial set of available classes to what it defines internally. The definition is static, but there are other ways to inject code into the class lookup mechanism inside the JVM which is where the classloaders come in. It's perfectly fine to reload any class at runtime, including the ones in a jar if they are defined in a classloader that you can control. There are two problems you have to overcome though. 1) If you want to change classes that are already loaded, one strategy is to hot swap the code (either via JVMTI, that's what you can do when you're in debug mode in an IDE, or you use JavaRebel (commercial), which goes a bit further in what you're able to redefine without killing the JVM, and losing state). Not sure if that's needed for Clojure code, since I haven't looked much at the bytecode so far, but it's really handy for Java and Scala for instance). 2) If you really need to add new things to the classpath (e.g. a new Jar), or you just want to reload a whole bunch of stuff, then you have to ditch the classloader that has these classes loaded (does not apply if you're adding new stuff), and add a new classloader that finds the new dependency at runtime. This is not that hard to do (check classloader javadoc), but it has quite a few cornercases, so it's not recommended to try it adhoc. There are systems that implement the whole system for you. Eclipse itself (the IDE, not the projects in it) can install plugins at runtime (although it asks you whether you want to restart), as can Maven (plugins are installed at runtime). The mechanism that supports this in Eclipse is OSGi (in Maven it's homegrown - classworlds), which is a nifty specification for dynamic service management inside the JVM. It can do a lot of things, but what is most interesting here is that it tracks versioned dependencies of runtime components. Think Maven or Ivy at runtime, and it's dynamically loading/unloading code based on what you specify. All of the OSGi implementations feature a management console (a REPL) where you can interact with the system at runtime (load and unload dependencies, it will warn if there are unmet dependencies etc.). I think making Clojure work well with OSGi is under 'longterm' on the roadmap, but I don't know what the current status is. I'm definitely giving it a vote though. Just to be clear, the classpath you define on the commandline is just a shortcut to define a classloader that looks up classes inside the jars and directories you define on the commandline. If you have your own classloaders (instantiated) you can load your code from a special directory (that's what the webcontainers (tomcat etc.) do to support hot redeployment of apps), the web (that's what applets do), a database (don't know who's doing that), an uncompiled script file (that's what scripting languages do unless they have precompiled to class files), or any other storage you can think of. The only requirement for a classloader is to return a bytearray that is valid java bytecode according to the spec, and it can only load the code once (it's cached after that, that's why you have to ditch the classloader). (And although the -cp argument supports wildcards since Java 1.6, they are expanded early and cannot be reevaluated during runtime :( ) More information available at: http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html So depending on your approach and what you want to be able to do (redefine/reload or add), it's a bit of work. The easiest thing is to unpack your
Re: Trouble specifying a gen-class constructor taking an argument of the class being created
I think you're right. Thanks. At this point I'll just work around it rather than patching, but it's good to know people are thinking about it---even if Rich has set the ticket to Backlog. And thanks Richard... I didn't even know PascalCase had a name =). On Wed, Jul 8, 2009 at 2:00 PM, Chouser chou...@gmail.com wrote: On Wed, Jul 8, 2009 at 7:57 AM, Garth Sheldon-Coulsong...@mit.edu wrote: Hello, Does anyone know a straightforward way to create a constructor using gen-class that takes an argument of the same class as the class you're generating? I think what you're describing is: http://www.assembla.com/spaces/clojure/tickets/84 --Chouser --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
On Wed, Jul 8, 2009 at 1:57 PM, Robert Campbell rrc...@gmail.com wrote: If it's okay, could somebody explain the difference between what's happening here: user (def my-func (list + 1 2)) #'user/my-func user (my-func) ; Evaluation aborted. and here: user (def my-func (list + 1 2)) #'user/my-func user (eval my-func) 3 I don't really understand how: user(my-func) is NOT eval on my-func in the REPL. My understanding is the first item in the list is treated as a function, with the rest of the list passed as arguments. Wouldn't the REPL just be calling eval internally on everything you type in? Not every expression is a function, even if most are function calls. Any expression can be evaluated with eval. To call something as a function, though, it has to be something invokable. A list, even a list of a function and two values, isn't. An actual function is, as produced by defn or fn or #(). So are sets, maps, and vectors, which will look up the argument key or index: user= (#{'x 'y} 'x) x user= (#{'x 'y} 'z) nil user= ({:key 'val} :key) val user= ({:key 'val} 3) nil user= (['a 'b 'c] 0) a user= (['a 'b 'c] 2) c user= (['a 'b 'c] 3) #CompilerException java.lang.ArrayIndexOutOfBoundsException: 3 (NO_SOURCE_FILE:0) And keywords can be invoked to do set and map lookups: user= (:key {:key 'val}) val user= (:x {:key 'val}) nil user= (:key #{:key}) :key user= (:x #{:key}) nil Last but not least, there's ., .., .methName, Class., Class/staticMeth, Class/staticField, and other variations on this theme to interact with Java classes. And maybe one or two things I'm forgetting. :) --~--~-~--~~~---~--~~ 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: zip of docs?
It looks like anyone with Organizer rights on Clojure's wikispaces wiki should be able to export an HTML or WikiText backup zip file. is that different than clojure.org? --~--~-~--~~~---~--~~ 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: Clojure cheat sheet
No no, that's not it. I merely suggested dzone.com because they generally promote their refcards, and I thought it would be a good way for clojure to get some press, and for you to get some fame. :) On Wed, Jul 8, 2009 at 1:49 PM, Steve Tayonsteve.ta...@googlemail.com wrote: On 8 Jul., 19:03, Wilson MacGyver wmacgy...@gmail.com wrote: Great idea, maybe you should talk to dzone.com about turning this into a refcard. You don't like the design, huh? I find it a little bit annoying, that I have to register to get their cheat sheets. So it is not as fast accessible as I would wish for. -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
Any expression can be evaluated with eval. As, indeed, can self-evaluating forms: user= (eval 3) 3 user= (eval (eval (eval (list + 1 2 3 user= (eval :foo) :foo user= (eval '+) #core$_PLUS___3949 clojure.core$_plus___3...@1d05c9a1 user= (eval 'eval) #core$eval__4610 clojure.core$eval__4...@4ef5c3a6 This kind of fiddling around in a REPL is very enlightening. --~--~-~--~~~---~--~~ 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: Help with example from A Field Guide to Genetic Programming
user (def my-func (list + 1 2)) #'user/my-func user (my-func) A list is not a function. Expanded: ((list + 1 2)) The first item in the outer list is a list, it is not a function. So to invoke the function you need to get it using first. Eval call on a list is evaluating a list, and the first item is a function so yup that works. It was bad (confusing) advice from me to store it like this really. You could just as easily used something like (let [my-fun {:fn +, :args [1 2]}] (apply (:fn my-fun) (:args my-fun))) The list approach is slightly more compact in that you can use eval and it 'looks' more lispy? Just a note, apply here isn't doing anything magical it is just unpacking the arguments to give (+ 1 2). user (def my-func (list + 1 2)) #'user/my-func user (eval my-func) 3 I don't really understand how: user(my-func) is NOT eval on my-func in the REPL. My understanding is the first item in the list is treated as a function, with the rest of the list passed as arguments. Wouldn't the REPL just be calling eval internally on everything you type in? Yes they are both evaluated, but they are different expressions: ((+ 1 2)) vs (+ 1 2) Regards, Tim. --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
On Jul 8, 4:57 pm, Frantisek Sodomka fsodo...@gmail.com wrote: So far it seems that vectors win in Clojure: (timings 3e5 (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c))) = 680.63 ms 83.6% 1.2x (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) 813.79 ms 100.0% 1.0x (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c)) Frantisek On Jul 8, 7:29 pm, John Harrop jharrop...@gmail.com wrote: Interesting. How are these timings affected if you add in the time taken to pack the list or vector in the first place, though? I have the feeling it may be slightly cheaper to unpack a vector, but noticeably cheaper to pack a list... I did some playing and it seems that the x-factor is really whether or not the array access function is in-lined into the code. I made a few tweaks to the source code so that the destructuring bind is able to rewrite the code with the 2-ary version and avoid rebinding overhead. I'll post it in reply to this. Here are some results I collected: (I like your 'timings' macro, by the way). (let [v [1 2 3] lst '(1 2 3)] (timings 1e7 (let [[a b c] v] a b c) (let [[a b c] #^{:length 3} v] a b c) (let [[a b c] #^{:tag :vector :length 3} v] a b c) (let [[a b c] #^{:length 3} [1 2 3]] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [a (first v) b (second v) c (first (rest (rest v)))] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z) (let [[a b c] lst] a b c) ;; (let [a (lst 0) b (lst 1) c (lst 2)] [a b c]) (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] a b c) (let [a (first lst) b (second lst) c (first (rest (rest lst)))] a b c) (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] x y z))) --- no inlining of 3-ary version (inlines 2ary version as normal), rewriting to 2-ary version dependant on :length :tag metadata and 4650.19 ms 34.2% 2.9x (let [[a b c] v] a b c) ;;nothing 3675.41 ms 27.0% 3.7x (let [[a b c] v] a b c) ;;length 3414.78 ms 25.1% 4.0x (let [[a b c] v] a b c) ;; tag length 13606.68 ms 100.0% 1.0x (let [[a b c] [1 2 3]] a b c) 3459.74 ms 25.4% 3.9x (let [a (v 0) b (v 1) c (v 2)] a b c) 3551.73 ms 26.1% 3.8x (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) 9810.52 ms 72.1% 1.4x (let [a (first v) b (second v) c (first (rest (rest v)))] a b c) 9234.34 ms 67.9% 1.5x (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z) 9519.99 ms 70.0% 1.4x (let [[a b c] lst] a b c) 7131.29 ms 52.4% 1.9x (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] a b c) 7665.99 ms 56.3% 1.8x (let [a (first lst) b (second lst) c (first (rest (rest lst)))] a b c) 7490.44 ms 55.0% 1.8x (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] x y z) --- inlining 3ary version, rewriting dependant on :length and :tag. 3230.53 ms 24.6% 4.1x (let [[a b c] v] a b c) ;;nothing 3557.94 ms 27.1% 3.7x (let [[a b c] v] a b c) ;;length 3287.01 ms 25.1% 4.0x (let [[a b c] v] a b c) ;;tag +length 13116.50 ms 100.0% 1.0x (let [[a b c] [1 2 3]] a b c) 3287.39 ms 25.1% 4.0x (let [a (v 0) b (v 1) c (v 2)] a b c) 3615.61 ms 27.6% 3.6x (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) 10634.64 ms 81.1% 1.2x (let [a (first v) b (second v) c (first (rest (rest v)))] a b c) 10147.02 ms 77.4% 1.3x (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z) 8476.63 ms 64.6% 1.5x (let [[a b c] lst] a b c) 7106.42 ms 54.2% 1.8x (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] a b c) 8172.17 ms 62.3% 1.6x (let [a (first lst) b (second lst) c (first (rest (rest lst)))] a b c) 8031.60 ms 61.2% 1.6x (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] x y z) I'll post the rather small tweaks in a response to this post. Please note that i was playing with a (month old) alpha 1.1 version of clojure.core, so I am not sure what the differences would be between it and a current version. I think the most interesting part is that you can get pretty much the same effect by just telling it to inline the 3ary version of nth. (Although it is a multi function, so it seems there is still some sort of funcall overhead). --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
Seperate so it can be easily ignored: Changed in core.clj: (defn nth Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences. {:inline (fn ([c i] `(. clojure.lang.RT (nth ~c ~i))) ([c i n] `(. clojure.lang.RT (nth ~c ~i ~n :inline-arities #{2 3}} ([coll index] (. clojure.lang.RT (nth coll index))) ([coll index not-found] (. clojure.lang.RT (nth coll index not- found ;;changed to inline the 3ary version of nth (defn destructure [bindings] (let [bmap (apply array-map bindings) pb (fn pb [bvec b v] (let [pvec (fn [bvec b val] (let [gvec (if (symbol? val) val (gensym vec__)), length-val (:length ^val)] (loop [ret (if (symbol? val) bvec (- bvec (conj gvec) (conj val))) n 0 bs b seen-rest? false] (if (seq bs) (let [firstb (first bs)] (cond (= firstb ') (recur (pb ret (second bs) (list `nthnext gvec n)) n (nnext bs) true) (= firstb :as) (pb ret (second bs) gvec) :else (if seen-rest? (throw (new Exception Unsupported binding form, only :as can follow parameter)) (recur (pb ret firstb (if (and length-val ( n length-val)) (if (or (vector? val)(= (:tag ^val) :vector)) (list gvec n) (list `nth gvec n)) (list `nth gvec n nil))) (inc n) (next bs) seen-rest? ret pmap (fn [bvec b v] (let [gmap (or (:as b) (if (symbol? v) v (gensym map__))) defaults (:or b)] (loop [ret (if (symbol? v) bvec (- bvec (conj gmap) (conj v))) bes (reduce (fn [bes entry] (reduce #(assoc %1 %2 ((val entry) %2)) (dissoc bes (key entry)) ((key entry) bes))) (dissoc b :as :or) {:keys #(keyword (str %)), :strs str, :syms #(list `quote %)})] (if (seq bes) (let [bb (key (first bes)) bk (val (first bes)) has-default (contains? defaults bb)] (recur (pb ret bb (if has-default (list `get gmap bk (defaults bb)) (list `get gmap bk))) (next bes))) ret] (cond (symbol? b) (- bvec (conj b) (conj v)) (vector? b) (pvec bvec b v) (map? b) (pmap bvec b v) :else (throw (new Exception (str Unsupported binding form: b)) process-entry (fn [bvec b] (pb bvec (key b) (val b)))] (if (every? symbol? (keys bmap)) bindings (reduce process-entry [] bmap ;;I wasn't sure how to do a 'vector' (kept getting the 'vector' function instead) so I just used ;;:vector keyword to dispatch on. Becomes kind of unsafe if you violate the 'length' promise. ;;this also eliminates a redundancy where you were binding (let [v [1 2 3]] (let [[a b c] v])) ;;and the inner let would have (let [gensym_vec v, a (nth gensym_vec 0)...]) ;;as opposed to (let [a (nth v 0)...]...) ;;which should be ok because we don't have to worry about multiple evaluation if we are destructuring from a symbol. --~--~-~--~~~---~--~~ 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
Re: Passing primitives from an inner loop to an outer loop efficiently
On Wed, Jul 8, 2009 at 4:57 PM, Frantisek Sodomka fsodo...@gmail.comwrote: So far it seems that vectors win in Clojure: (timings 3e5 (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c))) = 680.63 ms 83.6% 1.2x (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) 813.79 ms 100.0% 1.0x (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c)) Does using vec instead of vector make a difference? Using first, rest, first, rest instead of nth to destructure the list? --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
On Wed, Jul 8, 2009 at 2:56 PM, Mani dumb...@gmail.com wrote: Thanks Shawn, Robert. From Robert's post, I am bit confused here. I also read that .emacs is in %appdata% folder (vista), but all I see is .emacs.d folder (which I guess is for the emacs server). I tried creating one C-x C-f ~/.emacs - under my home-directory (C:\emacs). Should i just create a .emacs under %appdata%/.emacs.d OR right under %appdata%? Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where emacs thinks your home directory is. I would just go with that. It's normally in %appdata%, but it won't be there until you create it and save it. For ideas for a .emacs from scratch, you can look at http://bitbucket.org/shoover/emacs/src/tip/init.el. Shawn --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Idea for contrib.def: defmemo
In clojure.contrib.def, I'd love to have a defmemo macro that acts just like defn, only with memoize. I'm planning to change a lot of functions to use memoize, and I'm not looking forward to changing nice, clean defns with docstrings to (def {:doc docstring} function (memoize (fn ...)))s. Would this be useful for anyone else? --~--~-~--~~~---~--~~ 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: Clojure box - loading book examples from Programming Clojure
Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where emacs thinks your home directory is. I would just go with that. It's normally in %appdata%, but it won't be there until you create it and save it. yes, this is better than my #2 Robert? Is that all you have in your .emacs? I am looking to create one from scratch. Here is my entire .emacs file, which is extremely basic but got me up and running at least: -- (setq swank-clojure-extra-classpaths '()) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/clojure/clojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/jetty-6.1.16.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/jetty-util-6.1.16.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/servlet-api-2.5-20081211.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/commons-codec-1.3.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/commons-fileupload-1.2.1.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/commons-io-1.4.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/compojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/user/libs/postgresql-8.3-604.jdbc4.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Dev/technomancy-clojure-http-client/src) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(cua-mode t nil (cua-base)) '(show-paren-mode t)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) -- You'll notice the paths are different (I changed it during my first post) but obviously they aren't relevant. A big problem I had was getting versions of Clojure, Contrib, Compojure, Enlive, HttpClient, etc. that all play well with each other. I'd frequently have a version of Compojure/Enlive/HttpClient that was dependent on one or another Contrib version, etc. A quick trick I learned was to just check out Compojure from git, run the ant deps which downloads the dependencies compatible with that version, and just use those because James of Compojure has done the work syncing them all up, so: (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/compojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/clojure.jar) (add-to-list 'swank-clojure-extra-classpaths C:/Program Files/Clojure Box/compojure/deps/clojure-contrib.jar) But with 1.0 out now I haven't had as many issues. Rob On Thu, Jul 9, 2009 at 5:35 AM, Shawn Hoovershawn.hoo...@gmail.com wrote: On Wed, Jul 8, 2009 at 2:56 PM, Mani dumb...@gmail.com wrote: Thanks Shawn, Robert. From Robert's post, I am bit confused here. I also read that .emacs is in %appdata% folder (vista), but all I see is .emacs.d folder (which I guess is for the emacs server). I tried creating one C-x C-f ~/.emacs - under my home-directory (C:\emacs). Should i just create a .emacs under %appdata%/.emacs.d OR right under %appdata%? Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where emacs thinks your home directory is. I would just go with that. It's normally in %appdata%, but it won't be there until you create it and save it. For ideas for a .emacs from scratch, you can look at http://bitbucket.org/shoover/emacs/src/tip/init.el. Shawn --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ANN: Upcoming Clojure events (now with an 864 core Azul box)
Hello everyone, I thought I would take the liberty and announce a number of upcoming Clojure events. Rich Hickey is speaking at the JAOO Aarhus 2009 conference. Rich has two talks: * Introducing Clojure [http://jaoo.dk/aarhus-2009/presentation/ Introducing+Clojure] * The Clojure Concurrency Story [http://jaoo.dk/aarhus-2009/ presentation/The+Clojure+Concurrency+Story] I am particularly looking forward to the latter, which is in the Concurrency track that I am hosting (other notable speakers: Brian Goetz, Simon Peyton-Jones (Haskell) and Francesco Cesarini (Erlang)). Also the Danish Clojure Users' Group (dcug, http://clojure.org/community) is arranging a free Clojure Workshop at JAOO where Rich is also attending. We're not sure exactly what we will do for the event - so feedback is welcome. But I can say this: Azul Systems has agreed to let us access one of their Vega compute appliances (hwlab38 - Vega2, 768 core, 384G ram). Now that will be fun! Details: http://clojure.higher-order.net/?p=28 With DCUG, I will be giving two talks on Clojure – one in Copenhagen and one in Aarhus (that would be Denmark :-)) : Tuesday September 8th in Århus, 16:00 – 18:30 Wednesday September 9th in Copenhagen, 16:00 – 18:30 This event is also free - and an opportunity to meet other Clojure users. I haven’t decided on the exact topics yet. Also, I am hoping we can access the Azul box for this event also ;-) Finally, I have arranged a special discount on JAOO Aarhus 2009 tickets for DCUG members! Details will come soon, but we’re looking at a sweet 15%. If there ever was a doubt on whether you should attend JAOO it must be gone now ;-) News and updates: www.clojure.dk and http://jaoo.dk/aarhus-2009/ /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 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: ANN: Upcoming Clojure events (now with an 864 core Azul box)
Line break errors: On Jul 9, 6:34 am, Krukow karl.kru...@gmail.com wrote: * Introducing Clojure [http://jaoo.dk/aarhus-2009/presentation/ Introducing+Clojure] http://jaoo.dk/aarhus-2009/presentation/Introducing+Clojure * The Clojure Concurrency Story [http://jaoo.dk/aarhus-2009/ presentation/The+Clojure+Concurrency+Story] http://jaoo.dk/aarhus-2009/presentation/The+Clojure+Concurrency+Story /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 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 -~--~~~~--~~--~--~---