Re: Easy Way To Download Clojure Libraries From Git
Thanks! This is exactly what I was looking for. On Fri, Dec 3, 2010 at 6:12 PM, Alan Dipert wrote: > Hi, > David Liebke's cljr may meet your needs: https://github.com/liebke/cljr > > I also maintain a fork over at https://github.com/alandipert/cljr that > runs Clojure 1.3-alpha3. > > HTH, > Alan > > On Fri, Dec 3, 2010 at 9:04 PM, wrote: >> I second the recommendation to use leiningen. >> >> I can relate to your position of just wanting to play with the libraries and >> not being ready to create projects. >> >> But I'm not a classpath ninja of epic proportions. Really, I don't have a >> desire to be that. If you aren't either, you will want to use leiningen and >> create a project, following Sunil's instructions (and technomancy's readme >> at github is good for more detail/options). I found that for me, trying to >> use clojure without leiningen or a similar tool was a mistake. >> >> Thanks, >> Peter >> >> >> From: Sunil S Nandihalli >> Sender: clojure@googlegroups.com >> Date: Sat, 4 Dec 2010 07:12:23 +0530 >> To: >> ReplyTo: clojure@googlegroups.com >> Subject: Re: Easy Way To Download Clojure Libraries From Git >> Hi Asim, >> just do >> lein new >> and add >> [clojureql "1.0.0-beta2-SNAPSHOT"] to your dependencies in project.clj >> and run >> lein deps >> it will automatically download all the necessary dependencies. >> If you directly want to do it from github .. I don't know how to do that. >> Sunil. >> >> On Sat, Dec 4, 2010 at 6:23 AM, Asim Jalis wrote: >>> >>> Is there an easy way to download Clojure libraries from Git and to >>> play with them in the repl? >>> >>> It looks like all of them expect to be downloaded using leiningen, and >>> leiningen requires creating a project, with dependencies on specific >>> libraries. >>> >>> It would be nice if I could do something like: lein install >>> https://github.com/LauJensen/clojureql and it would just grab it and >>> install it and all its dependencies. >>> >>> My goal is just to play with different libraries -- I am not consuming >>> them in projects yet. >>> >>> Asim >>> >>> -- >>> 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 >> >> -- >> 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 >> >> -- >> 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 > > -- > 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 -- 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: what does the value part of &env map automatically passed to all macros contain?
I feel they could add a flag to indicate if it was obtained via gensym or not.. I would have liked to have it in the past. It can help in writing debug macros .. may be give better debug messages etc. Sunil On Sat, Dec 4, 2010 at 9:29 AM, Alex Osborne wrote: > Sunil S Nandihalli writes: > > > I really like the &env. It has saved a lot of tedious work a couple of > > times .. but I have only found use for the keys of the map that gets > > passed like in the following example. > > > I don't understand what the val part of the map contains? I have > > failed at attempts to figuring it out.. Can somebody tell me what the > > val part contains and how one could use it? > > It contains a LocalBindings object which the compiler uses internally to > keep track of a local binding. Note that unlike the keys, the values of > &env are not a stable API, they're implementation details and may well > change. When he added &env I think Rich said he'd look at giving the > values of &env a proper API as part of the future Clojure in Clojure > compiler. > > But you can poke at them like this: > > (defmacro foo [] > (def lb (first (vals &env > > (let [a (+ 1 3)] > (foo)) > > (.sym lb) > ;; a > > (.idx lb) > ;; 1 > > (.name lb) > ;; "a" > > (.isArg lb) > ;; false > > (.canBeCleared lb) > ;; true > > (.init lb) > ;; # ;; clojure.lang.compiler$staticmethode...@1a9d267d> > > (.args (.init lb)) > ;; [# > ;; #] > > > If you're using Emacs + SLIME, the SLIME inspector is quite useful for > exploring unknown values. After evaling the first two forms above, put > the cursor over "lb" and press C-c I (note that's shift + i). You'll > get something like this: > > clojure.lang.compiler$localbind...@25de152f > > Type: class clojure.lang.Compiler$LocalBinding > Value: clojure.lang.compiler$localbind...@25de152f > --- > Fields: > sym: a > tag: > init: clojure.lang.compiler$staticmethode...@1a9d267d > idx: 1 > name: a > isArg: false > clearPathRoot: clojure.lang.compiler$pathn...@1740d415 > canBeCleared: true > > You can then press enter on any of the field values or class names to > get more detail about them. > > -- > 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 -- 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: what does the value part of &env map automatically passed to all macros contain?
Thanks Alex. I asked because I thought it might be part of stable API. Thanks for your tip on slime (I do use slime) also. I will wait for it to become part of stable api. Sunil. On Sat, Dec 4, 2010 at 9:29 AM, Alex Osborne wrote: > Sunil S Nandihalli writes: > > > I really like the &env. It has saved a lot of tedious work a couple of > > times .. but I have only found use for the keys of the map that gets > > passed like in the following example. > > > I don't understand what the val part of the map contains? I have > > failed at attempts to figuring it out.. Can somebody tell me what the > > val part contains and how one could use it? > > It contains a LocalBindings object which the compiler uses internally to > keep track of a local binding. Note that unlike the keys, the values of > &env are not a stable API, they're implementation details and may well > change. When he added &env I think Rich said he'd look at giving the > values of &env a proper API as part of the future Clojure in Clojure > compiler. > > But you can poke at them like this: > > (defmacro foo [] > (def lb (first (vals &env > > (let [a (+ 1 3)] > (foo)) > > (.sym lb) > ;; a > > (.idx lb) > ;; 1 > > (.name lb) > ;; "a" > > (.isArg lb) > ;; false > > (.canBeCleared lb) > ;; true > > (.init lb) > ;; # ;; clojure.lang.compiler$staticmethode...@1a9d267d> > > (.args (.init lb)) > ;; [# > ;; #] > > > If you're using Emacs + SLIME, the SLIME inspector is quite useful for > exploring unknown values. After evaling the first two forms above, put > the cursor over "lb" and press C-c I (note that's shift + i). You'll > get something like this: > > clojure.lang.compiler$localbind...@25de152f > > Type: class clojure.lang.Compiler$LocalBinding > Value: clojure.lang.compiler$localbind...@25de152f > --- > Fields: > sym: a > tag: > init: clojure.lang.compiler$staticmethode...@1a9d267d > idx: 1 > name: a > isArg: false > clearPathRoot: clojure.lang.compiler$pathn...@1740d415 > canBeCleared: true > > You can then press enter on any of the field values or class names to > get more detail about them. > > -- > 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 -- 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: why not change > < type compare functions do a compare on strings as well?
Hi ka, I do already use compare in my functions, but compare alone is costly to performance and isn't as meaningful given it doesn't evaluate true/ false. It's really just about convenience and code-readability while trying not to sacrifice too much speed. To give you an example here's my over-riding Clojure defaults in a patch file: (defn > [x y] (if (coll? y) (if (string? x) (empty? (filter #(. clojure.lang.Numbers (isNeg (.compareTo x %))) y)) (empty? (filter #(. clojure.lang.Numbers (gt % x)) y))) (if (string? x) (. clojure.lang.Numbers (isPos (.compareTo x y))) (. clojure.lang.Numbers (gt x y) (defn < [x y] (if (coll? y) (if (string? x) (empty? (filter #(. clojure.lang.Numbers (isPos (.compareTo x %))) y)) (empty? (filter #(. clojure.lang.Numbers (lt % x)) y))) (if (string? x) (. clojure.lang.Numbers (isNeg (.compareTo x y))) (. clojure.lang.Numbers (lt x y) Using these I can write shorter, more readable code. So let's compare the two: (if (> "2010-11-01" ["2010-06-09" "2010-06-08" "2010-06-04" "2010-06-10"]) (run-my-function-to-upate-data)) vs. (if (empty? (filter #(neg? (compare "2010-11-01" %))["2010-06-09" "2010-06-08" "2010-06-04" "2010-06-10"])) (run-my-function-to-upate-data)) ~ there's probably 10 different other ways to write the above, but it's an example. So while this may seem trivial to many, cumulatively I have quite a few of these functions built that have helped me not only cut my code size in half, but have made my code really easy to read and maintain. Furthermore my rule is to favour code readability and only optimize performance when meaningfully required. P.S. It's also worth noting that while my version of > is uglier and longer than say: (defn > [x y] (if (coll? y) (empty? (filter #(. clojure.lang.Numbers (isNeg (.compareTo x %))) y)) (. clojure.lang.Numbers (isPos (.compareTo x y) My version performs well. Using (compare n) on a number is much more costly than doing a string check. Since I use it as a library function I never have to see it's ugliness. :) On Dec 3, 7:47 pm, ka wrote: > Hi Tim, > > How about compare? > > user=> (compare "a" "b") > -1 > user=> (compare "b" "b") > 0 > user=> (compare "b" "a") > 1 > user=> (compare 1 2) > -1 > user=> (compare 2 2) > 0 > user=> (compare 2 1) > 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: what does the value part of &env map automatically passed to all macros contain?
Sunil S Nandihalli writes: > I really like the &env. It has saved a lot of tedious work a couple of > times .. but I have only found use for the keys of the map that gets > passed like in the following example. > I don't understand what the val part of the map contains? I have > failed at attempts to figuring it out.. Can somebody tell me what the > val part contains and how one could use it? It contains a LocalBindings object which the compiler uses internally to keep track of a local binding. Note that unlike the keys, the values of &env are not a stable API, they're implementation details and may well change. When he added &env I think Rich said he'd look at giving the values of &env a proper API as part of the future Clojure in Clojure compiler. But you can poke at them like this: (defmacro foo [] (def lb (first (vals &env (let [a (+ 1 3)] (foo)) (.sym lb) ;; a (.idx lb) ;; 1 (.name lb) ;; "a" (.isArg lb) ;; false (.canBeCleared lb) ;; true (.init lb) ;; # (.args (.init lb)) ;; [# ;; #] If you're using Emacs + SLIME, the SLIME inspector is quite useful for exploring unknown values. After evaling the first two forms above, put the cursor over "lb" and press C-c I (note that's shift + i). You'll get something like this: clojure.lang.compiler$localbind...@25de152f Type: class clojure.lang.Compiler$LocalBinding Value: clojure.lang.compiler$localbind...@25de152f --- Fields: sym: a tag: init: clojure.lang.compiler$staticmethode...@1a9d267d idx: 1 name: a isArg: false clearPathRoot: clojure.lang.compiler$pathn...@1740d415 canBeCleared: true You can then press enter on any of the field values or class names to get more detail about them. -- 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: resultset-seq improvement: mapping column names
I'm also stuck with the same issues: 1. no option to get string keys 2. I don't understand, why do libs go through the trouble of downcasing ? Having said that I totally agree with the point Ryan makes: >> A greater feature of clojure is its extensibility. What I am after is a generalization of the function in question, for greater interoperability with Java's SQL libraries. -- 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: functional thinking
Hi Michael, We're in a very similar situation to yours. Here's what we did: 1. 2 back end storage impls rah.storage1, rah.storage2 - these are "private" nses. 2. a single storage interface rah.storage for the rest of the business code. At runtime this decides which of storage1 or 2 to call. 3. Now you can implement 2. in many ways, protocol, multimethods, global vars etc. We chose multimethods + macros to generate defmethod calls automatically. @ Laurent, Ken, Why not wrap the entry point in bound-fn ? Convenience? -- 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: when to use io! macro?
What I said is purely from reading the documentation .. I have never ever used it. Take it with a pinch of salt! On Sat, Dec 4, 2010 at 8:40 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > It gives a convenience macro which checks if there is a transaction running > when the following code block is called. The idea is that since the code in > a transaction could be called a multiple times, you should not do things > like sending things on to the network or writing to a file during a > transaction. So what you should do is wrap any network/ InputOutput > operation in a io! macro. If you did that .. if you call this function > inside a transaction it would throw an exception. > > > On Sat, Dec 4, 2010 at 8:29 AM, ka wrote: > >> This is a good question and I'm not sure of the right answer or if >> there is one. Personally, if I were exposing an API I would use the >> io! macro for sure. Even otherwise its a good convention to follow. >> >> On Nov 30, 9:06 am, Alex Baranosky >> wrote: >> > Hi guys, >> > >> > I've recently discovered the io! macro. Is this something to try to use >> all >> > the time.. or only in certain situations? >> > >> > Alex >> >> -- >> 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 >> > > -- 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: when to use io! macro?
It gives a convenience macro which checks if there is a transaction running when the following code block is called. The idea is that since the code in a transaction could be called a multiple times, you should not do things like sending things on to the network or writing to a file during a transaction. So what you should do is wrap any network/ InputOutput operation in a io! macro. If you did that .. if you call this function inside a transaction it would throw an exception. On Sat, Dec 4, 2010 at 8:29 AM, ka wrote: > This is a good question and I'm not sure of the right answer or if > there is one. Personally, if I were exposing an API I would use the > io! macro for sure. Even otherwise its a good convention to follow. > > On Nov 30, 9:06 am, Alex Baranosky > wrote: > > Hi guys, > > > > I've recently discovered the io! macro. Is this something to try to use > all > > the time.. or only in certain situations? > > > > Alex > > -- > 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 > -- 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: dosync style
On 29 November 2010 16:33, Stuart Halloway wrote: > I must respectfully disagree with James's first point here. The first pattern > (read-ponder-update) is not concurrency-friendly. It isn't about atom vs. > ref, the important distinction is whether all the work can be done in a > function that gets sent *to* the ref. The latter formulation also can be > extracted into a pure function, which is easier to test. Good point. I wasn't thinking in terms of concurrency performance. - James -- 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
what does the value part of &env map automatically passed to all macros contain?
Hello everybody, I really like the &env. It has saved a lot of tedious work a couple of times .. but I have only found use for the keys of the map that gets passed like in the following example. (defmacro display-local-bindings [] `(do ~@(map (fn [x#] (list 'println [`'~x# x#])) (keys &env (let [x 10 y 20] (display-local-bindings)) would print [x 10] [y 20] I don't understand what the val part of the map contains? I have failed at attempts to figuring it out.. Can somebody tell me what the val part contains and how one could use it? Thanks, Sunil. -- 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: when to use io! macro?
This is a good question and I'm not sure of the right answer or if there is one. Personally, if I were exposing an API I would use the io! macro for sure. Even otherwise its a good convention to follow. On Nov 30, 9:06 am, Alex Baranosky wrote: > Hi guys, > > I've recently discovered the io! macro. Is this something to try to use all > the time.. or only in certain situations? > > Alex -- 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: why not change > < type compare functions do a compare on strings as well?
Hi Tim, How about compare? user=> (compare "a" "b") -1 user=> (compare "b" "b") 0 user=> (compare "b" "a") 1 user=> (compare 1 2) -1 user=> (compare 2 2) 0 user=> (compare 2 1) 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: Easy Way To Download Clojure Libraries From Git
Hi, David Liebke's cljr may meet your needs: https://github.com/liebke/cljr I also maintain a fork over at https://github.com/alandipert/cljr that runs Clojure 1.3-alpha3. HTH, Alan On Fri, Dec 3, 2010 at 9:04 PM, wrote: > I second the recommendation to use leiningen. > > I can relate to your position of just wanting to play with the libraries and > not being ready to create projects. > > But I'm not a classpath ninja of epic proportions. Really, I don't have a > desire to be that. If you aren't either, you will want to use leiningen and > create a project, following Sunil's instructions (and technomancy's readme > at github is good for more detail/options). I found that for me, trying to > use clojure without leiningen or a similar tool was a mistake. > > Thanks, > Peter > > > From: Sunil S Nandihalli > Sender: clojure@googlegroups.com > Date: Sat, 4 Dec 2010 07:12:23 +0530 > To: > ReplyTo: clojure@googlegroups.com > Subject: Re: Easy Way To Download Clojure Libraries From Git > Hi Asim, > just do > lein new > and add > [clojureql "1.0.0-beta2-SNAPSHOT"] to your dependencies in project.clj > and run > lein deps > it will automatically download all the necessary dependencies. > If you directly want to do it from github .. I don't know how to do that. > Sunil. > > On Sat, Dec 4, 2010 at 6:23 AM, Asim Jalis wrote: >> >> Is there an easy way to download Clojure libraries from Git and to >> play with them in the repl? >> >> It looks like all of them expect to be downloaded using leiningen, and >> leiningen requires creating a project, with dependencies on specific >> libraries. >> >> It would be nice if I could do something like: lein install >> https://github.com/LauJensen/clojureql and it would just grab it and >> install it and all its dependencies. >> >> My goal is just to play with different libraries -- I am not consuming >> them in projects yet. >> >> Asim >> >> -- >> 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 > > -- > 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 > > -- > 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 -- 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: Easy Way To Download Clojure Libraries From Git
I second the recommendation to use leiningen. I can relate to your position of just wanting to play with the libraries and not being ready to create projects. But I'm not a classpath ninja of epic proportions. Really, I don't have a desire to be that. If you aren't either, you will want to use leiningen and create a project, following Sunil's instructions (and technomancy's readme at github is good for more detail/options). I found that for me, trying to use clojure without leiningen or a similar tool was a mistake. Thanks, Peter -Original Message- From: Sunil S Nandihalli Sender: clojure@googlegroups.com Date: Sat, 4 Dec 2010 07:12:23 To: Reply-To: clojure@googlegroups.com Subject: Re: Easy Way To Download Clojure Libraries From Git Hi Asim, just do lein new and add [clojureql "1.0.0-beta2-SNAPSHOT"] to your dependencies in project.clj and run lein deps it will automatically download all the necessary dependencies. If you directly want to do it from github .. I don't know how to do that. Sunil. On Sat, Dec 4, 2010 at 6:23 AM, Asim Jalis wrote: > Is there an easy way to download Clojure libraries from Git and to > play with them in the repl? > > It looks like all of them expect to be downloaded using leiningen, and > leiningen requires creating a project, with dependencies on specific > libraries. > > It would be nice if I could do something like: lein install > https://github.com/LauJensen/clojureql and it would just grab it and > install it and all its dependencies. > > My goal is just to play with different libraries -- I am not consuming > them in projects yet. > > Asim > > -- > 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 -- 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 -- 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: dosync style
> (defn dec-or-dissoc! [key] > (dosync >(let [n (@*counts* key)] > (if (< 1 n) >(alter *counts* assoc key (dec n)) >(alter *counts* dissoc key) > Is it true that in that case, one would have to use "ensure" to make the > operation correct? I don't think ensure is necessary here, coz the *counts* gets altered in all cases. Whereas consider this: (defn dec-or-dissoc! [key] (dosync (let [n (@*counts* key)] (when (< 1 n) (alter *counts* assoc key (dec n)) In this case I think ensure is necessary. Now consider this, (defn dec-or-dissoc! [key] (dosync (alter *counts* (fn [m] (let [n (m key)] (when (< 1 n) (assoc m key (dec n In this case ensure is not necessary. -- 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: Easy Way To Download Clojure Libraries From Git
Hi Asim, just do lein new and add [clojureql "1.0.0-beta2-SNAPSHOT"] to your dependencies in project.clj and run lein deps it will automatically download all the necessary dependencies. If you directly want to do it from github .. I don't know how to do that. Sunil. On Sat, Dec 4, 2010 at 6:23 AM, Asim Jalis wrote: > Is there an easy way to download Clojure libraries from Git and to > play with them in the repl? > > It looks like all of them expect to be downloaded using leiningen, and > leiningen requires creating a project, with dependencies on specific > libraries. > > It would be nice if I could do something like: lein install > https://github.com/LauJensen/clojureql and it would just grab it and > install it and all its dependencies. > > My goal is just to play with different libraries -- I am not consuming > them in projects yet. > > Asim > > -- > 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 -- 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
Easy Way To Download Clojure Libraries From Git
Is there an easy way to download Clojure libraries from Git and to play with them in the repl? It looks like all of them expect to be downloaded using leiningen, and leiningen requires creating a project, with dependencies on specific libraries. It would be nice if I could do something like: lein install https://github.com/LauJensen/clojureql and it would just grab it and install it and all its dependencies. My goal is just to play with different libraries -- I am not consuming them in projects yet. Asim -- 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: Tailing a file in Clojure
On Dec 3, 4:42 am, Alex Osborne wrote: > patrickdlogan writes: > > Java has a file watch API to avoid polling. > > I assume you're talking about the NIO 2 watch service? That's not > yet in a released version of Java, it's coming in Java 7. oh I see. -- 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: Quene in Clojure
It is not a shared, concurrent data structure. In and of itself it can not be used to mutate a shared collection of data. You could use something like Java's ConcurrentLinkedQueue. On Dec 3, 2:17 pm, Andreas Kostler wrote: > Hi All, > May I cite an Author of a populer Clojure book: > > "If you find yourself wishing yourself to repeatedly check a work > queue to see if there's an item of work to be popped off, > or if you want to use a queue to send a task to another thread, you do > *not* want the PersistenQueue discussed in this section" > > Why do I not want to use clojure.lang.PersistentQueue for that purpose > and what would I want to use instead? > Can anyone fill me in please? -- 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: more idiomatic clojure
hmmm, seems like you, me and rayne all fail to handle the overlapping node case correctly. this is the best solution i've come up with that actually seems to work: (apply merge-with concat {} (for [nd d nd-pair nd face nd-pair] {face (list nd)})) try it with d set to this: [d [#{#{1 2} #{3 5}} #{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]] On Dec 3, 2:00 pm, George Jahad wrote: > Actually my solution is wrong! It works for this particular example, > but not if there are nodes with overlapping values. > Doh! > > My main point was just that "into" is a under used gem, that I wanted > to publicize a bit. Next time I'll try to find an example that is > actually correct! > > On Dec 3, 12:46 pm, Laurent PETIT wrote: > > > Yes, > > > though I've always found 'into a little bit too magical for me. > > For example, I find it hard to follow the doc to see what 'adding' will mean > > for maps. > > > 2010/12/3 George Jahad > > > > > (apply > > > > merge-with > > > > conj > > > > {} > > > > (for [nd d nd-pair nd face nd-pair] > > > > {face nd})) > > > > I like to use into for cases like this: > > > > (into {} (for [nd d nd-pair nd face nd-pair] [face nd])) > > > > seems clearer to me. > > > > g > > > > -- > > > 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 -- 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
Quene in Clojure
Hi All, May I cite an Author of a populer Clojure book: "If you find yourself wishing yourself to repeatedly check a work queue to see if there's an item of work to be popped off, or if you want to use a queue to send a task to another thread, you do *not* want the PersistenQueue discussed in this section" Why do I not want to use clojure.lang.PersistentQueue for that purpose and what would I want to use instead? Can anyone fill me in please? -- 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: more idiomatic clojure
Actually my solution is wrong! It works for this particular example, but not if there are nodes with overlapping values. Doh! My main point was just that "into" is a under used gem, that I wanted to publicize a bit. Next time I'll try to find an example that is actually correct! On Dec 3, 12:46 pm, Laurent PETIT wrote: > Yes, > > though I've always found 'into a little bit too magical for me. > For example, I find it hard to follow the doc to see what 'adding' will mean > for maps. > > 2010/12/3 George Jahad > > > > > > (apply > > > merge-with > > > conj > > > {} > > > (for [nd d nd-pair nd face nd-pair] > > > {face nd})) > > > I like to use into for cases like this: > > > (into {} (for [nd d nd-pair nd face nd-pair] [face nd])) > > > seems clearer to me. > > > g > > > -- > > 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 -- 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: Creating map from string
2010/12/3 Ken Wesson > Object creation wasn't my concern -- modern JVMs are very efficient in > that regard -- just traversals. > Ken, I've done my "homework", and of course you were right, and me wrong. At some point in my reasoning I've conflated number of object allocations with number of traversals, and I was off track. Cheers, -- 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: more idiomatic clojure
Yes, though I've always found 'into a little bit too magical for me. For example, I find it hard to follow the doc to see what 'adding' will mean for maps. 2010/12/3 George Jahad > > > (apply > > merge-with > > conj > > {} > > (for [nd d nd-pair nd face nd-pair] > > {face nd})) > > I like to use into for cases like this: > > (into {} (for [nd d nd-pair nd face nd-pair] [face nd])) > > > seems clearer to me. > > g > > -- > 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 > -- 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: more idiomatic clojure
> (apply > merge-with > conj > {} > (for [nd d nd-pair nd face nd-pair] > {face nd})) I like to use into for cases like this: (into {} (for [nd d nd-pair nd face nd-pair] [face nd])) seems clearer to me. g -- 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: Creating map from string
Object creation wasn't my concern -- modern JVMs are very efficient in that regard -- just traversals. -- 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: Tailing a file in Clojure
This is being added with JSR 203 in Java 7: - http://java.dzone.com/articles/introducing-nio2-jsr-203-part-2 There was a backport for JDK 6 started: http://code.google.com/p/jsr203-backport/ but I don't think it's been touched in a couple years. On Dec 3, 1:20 pm, Stuart Sierra wrote: > On Dec 2, 10:55 pm, patrickdlogan wrote: > > > Java has a file watch API to avoid polling. Stuart Sierra uses it to > > good effect in lazytest. > > No, there is no such Java API that I am aware of. Lazytest watches > the filesystem by polling. > > -S -- 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: Creating map from string
2010/12/3 Ken Wesson > On Fri, Dec 3, 2010 at 10:08 AM, Laurent PETIT > wrote: > > 2010/12/3 Laurent PETIT > >> 2010/12/3 Anclj > >>> I've got: > >>> > >>> user> (split (slurp "data") #",") > >>> ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] > >>> > >>> And I would like: > >>> {:0 2, :1 5, :2 8, :3 15, :4 9} > >>> > >>> Any idea? > >> > >> > >> (let [s (split (slurp "data") #",")] > >> (zipmap (take-nth 2 s) (take-nth 2 (rest s > > > > Sorry, this respects the contract better: > > > > (let [s ["1" "2" "3" "4" "5" "6"]] > > (zipmap > > (map keyword (take-nth 2 s)) > > (map #(Integer/valueOf %) (take-nth 2 (rest s) > > Both of these traverse s twice. How about: > > (let [s (split (slurp "data") #",")] > (into {} >(map (fn [[k v]] [(keyword (str k)) v]) > (partition 2 s > Indeed, if I analyze my solution: the 2 take-nth traverse s 2 times (creating 2 x 1/2 x n ISeq instances), and the two maps over the 2 resulting seq traverse these resulting seqs also, creating again 2 x 1/2 x n ISeq instances). In the end, 2 x 1/2 x n + 2 x 1/2 x n = 2 x n ISeq instances are created and visited. Now yours :-) : (partition 2 s) traverses s once, and creates 1/2 n ISeq instances each made of a seq of 2 ISeq instances => 1/2 n x 2 = n ISeq instances. Then map is applied and creates 1/2 x n vectors in 1/2 x n ISeq instances => also n instances created. In the end, your solution also creates 2 x n instances (ISeq instances and vector instances), before being consumed by into. In fact, when one knows the algorithm needs to consume the entire seq *by definition* (since in clojure datastructures themselves are not lazy, only seqs are), it sometimes feels odd to create all these intermediate objects. But I generally resist the temptation to too quickly resort to using loop, which is the real solution to not create too many intermediate objects: (let [s ["1" "2" "3" "4" "5" "6" "7" "8"]] (loop [s (seq s) m {}] (if s (recur (nnext s) (assoc m (keyword (first s)) (Integer/valueOf (fnext s m))) or else by leveraging transients: (let [s ["1" "2" "3" "4" "5" "6" "7" "8"]] (loop [s (seq s) m (transient {})] (if s (recur (nnext s) (assoc! m (keyword (first s)) (Integer/valueOf (fnext s (persistent! m But really I generally not start (anymore) writing loops unless I see a performance problem! -- 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: Tailing a file in Clojure
On Dec 2, 10:55 pm, patrickdlogan wrote: > Java has a file watch API to avoid polling. Stuart Sierra uses it to > good effect in lazytest. No, there is no such Java API that I am aware of. Lazytest watches the filesystem by polling. -S -- 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: more idiomatic clojure
As a general rule, if you have something that has the semantics of a pure function, and you can see how to implement it by banging on an atom with swap! in a loop that consumes a sequence, then you can transform it to use reduce. If you have: (defn foo [coll] (let [x (atom bar)] (dorun [y coll] (swap! x f y)) @x)) you can change it to: (defn foo [coll] (reduce f bar 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: Creating map from string
On Fri, Dec 3, 2010 at 10:08 AM, Laurent PETIT wrote: > 2010/12/3 Laurent PETIT >> 2010/12/3 Anclj >>> I've got: >>> >>> user> (split (slurp "data") #",") >>> ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] >>> >>> And I would like: >>> {:0 2, :1 5, :2 8, :3 15, :4 9} >>> >>> Any idea? >> >> >> (let [s (split (slurp "data") #",")] >> (zipmap (take-nth 2 s) (take-nth 2 (rest s > > Sorry, this respects the contract better: > > (let [s ["1" "2" "3" "4" "5" "6"]] > (zipmap > (map keyword (take-nth 2 s)) > (map #(Integer/valueOf %) (take-nth 2 (rest s) Both of these traverse s twice. How about: (let [s (split (slurp "data") #",")] (into {} (map (fn [[k v]] [(keyword (str k)) v]) (partition 2 s -- 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: implementing nth for sorted-set and sorted-map
On Fri, Dec 3, 2010 at 2:27 AM, Sunil S Nandihalli wrote: > Right now I am just seq ing it before using nth > Sunil. The real oddity here is that nth doesn't seem to call seq on its argument. It probably should (for non-vector arguments). -- 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
outlining for clojure files in emacs+slime?
Hello everybody, I would like to know if any of you are using any outlining mode in emacs+slime.. if so how? Thanks, Sunil. -- 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: more idiomatic clojure
thanks Rayne. On Fri, Dec 3, 2010 at 4:02 PM, Rayne wrote: > Here is what I came up with. > > (let [d [#{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]] > (reduce > (fn [mp nd] > (apply merge >(for [nd-pair nd face nd-pair] (update-in mp [face] #(conj > % nd) {} d)) > > On Dec 3, 3:42 am, Sunil S Nandihalli > wrote: > > Hello everybody, > > I would like to know as to how I would write the following code in a > > more idiomatic way. > > > > (let [mp (atom {}) > > d [#{#{1 2} > >#{3 4}} ;node1 > > #{#{5 6} > >#{7 8}} ;node2]] > > (dorun (for [nd d nd-pair nd face nd-pair] > >(swap! mp update-in [face] #(conj % nd > > @mp) > > > > ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 > > form node2 > > ;I would like a map in the opposite direction .. > > ;i.e. I should be able to find out all the nodes of which 1 is part of > and > > ;that is what the above code is doing.. but would like to know as to what > > ;would be a more idiomatic way of doing this. > > > > https://gist.github.com/726773 > > > > I don't like the fact that I am using atom and swap .. can anybody > > suggest a better way to do it? > > > > Thanks, > > Sunil. > > -- > 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 > -- 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: Creating map from string
2010/12/3 Laurent PETIT > Hi, > > 2010/12/3 Anclj > > Hi, >> >> I have a string of data and I would like to get a map {:key >> value, :key value, …} >> >> How could I do that? >> >> I've got: >> >> user> (split (slurp "data") #",") >> ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] >> >> And I would like: >> {:0 2, :1 5, :2 8, :3 15, :4 9} >> >> Any idea? >> > > > (let [s (split (slurp "data") #",")] > (zipmap (take-nth 2 s) (take-nth 2 (rest s > > Sorry, this respects the contract better: (let [s ["1" "2" "3" "4" "5" "6"]] (zipmap (map keyword (take-nth 2 s)) (map #(Integer/valueOf %) (take-nth 2 (rest s) -- 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: Creating map from string
Here is what I came up with ... (let [d (split (slurp "data") #",")] (->> d (apply hash-map) (clojure.walk/keywordize-keys) (clojure.contrib.generic.functor/fmap read-string))) Sunil. On Fri, Dec 3, 2010 at 7:52 PM, Anclj wrote: > Hi, > > I have a string of data and I would like to get a map {:key > value, :key value, …} > > How could I do that? > > I've got: > > user> (split (slurp "data") #",") > ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] > > And I would like: > {:0 2, :1 5, :2 8, :3 15, :4 9} > > Any idea? > 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 -- 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: Creating map from string
Hi, 2010/12/3 Anclj > Hi, > > I have a string of data and I would like to get a map {:key > value, :key value, …} > > How could I do that? > > I've got: > > user> (split (slurp "data") #",") > ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] > > And I would like: > {:0 2, :1 5, :2 8, :3 15, :4 9} > > Any idea? > (let [s (split (slurp "data") #",")] (zipmap (take-nth 2 s) (take-nth 2 (rest s HTH, -- 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: Wolfram: 100 years since Principia Mathematica
> He may have some interesting points but... > > Anyone who makes grandiose claims and can't bother to give credit to > the people who have helped them along the way deserves to be ignored. My feelings exactly. His perception of himself seems self-aggrandizing as well. Why is John Carmack the only person to have made millions on software that he later open-sourced?? Just my two cents. -- 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
Creating map from string
Hi, I have a string of data and I would like to get a map {:key value, :key value, …} How could I do that? I've got: user> (split (slurp "data") #",") ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] And I would like: {:0 2, :1 5, :2 8, :3 15, :4 9} Any idea? 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: Tailing a file in Clojure
patrickdlogan writes: > Java has a file watch API to avoid polling. I assume you're talking about the NIO 2 watch service? That's not yet in a released version of Java, it's coming in Java 7. > Stuart Sierra uses it to good effect in lazytest. It looks to me like lazytest polls the last modified date every 500 ms. http://github.com/stuartsierra/lazytest/blob/master/modules/lazytest/src/main/clojure/lazytest/watch.clj -- 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: Queues in Clojure
2010/12/3 Andreas Kostler : > Hi All, > May I cite an Author of a populer Clojure book: > > "If you find yourself wishing yourself to repeatedly check a work queue to > see if there's an item of work to be popped off, > or if you want to use a queue to send a task to another thread, you do *not* > want the PersistenQueue discussed in this section" > > Why do I not want to use clojure.lang.PersistentQueue for that purpose and > what would I want to use instead? > Can anyone fill me in please? clojure.lang.PersistentQueue is a collection data structure with queue operations. It is persistent, so it lets you (and other threads) create modified versions of it with elements enqueued or dequeued in a thread-safe manner. java.util.concurrent.LinkedBlockingQueue[1] is not a persistent data structure. It is often used as a communication channel between threads, since it allows its operations to block (potentially with a timeout). One thread can dequeue (and block if the queue is empty) simultaneously as another thread can enqueue (and block if the queue is full) at the other end. It makes it easy to make programs in a producer-consumer style. // raek [1] http://download.oracle.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.html -- 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: Tailing a file in Clojure
On Dec 2, 8:53 am, viksit wrote: > Hi all, > > What would you recommend as the best method to tail a file using > Clojure? Are there any built in functions in contrib or core that > allow a program to read the last line of a file as it is appended to? > If not - how do people solve a problem like this? > > My aim is simple - I've got a log file and I'd like to parse it as it > gets appended to. > I have had to do this in the past and I use unix commands: https://gist.github.com/726875 The code above runs a unix command in a separate thread and executes a given function, f, on a sequence of output lines. It handles restarts if the command gets killed by a log rotation. For the actual tail command I'd recommend looking at a recent version of GNU tail or install inotail - a filewatching API which makes these commands much more efficient: http://distanz.ch/inotail/ Saul -- 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
Queues in Clojure
Hi All, May I cite an Author of a populer Clojure book: "If you find yourself wishing yourself to repeatedly check a work queue to see if there's an item of work to be popped off, or if you want to use a queue to send a task to another thread, you do *not* want the PersistenQueue discussed in this section" Why do I not want to use clojure.lang.PersistentQueue for that purpose and what would I want to use instead? Can anyone fill me in please? -- 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: more idiomatic clojure
Here is what I came up with. (let [d [#{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]] (reduce (fn [mp nd] (apply merge (for [nd-pair nd face nd-pair] (update-in mp [face] #(conj % nd) {} d)) On Dec 3, 3:42 am, Sunil S Nandihalli wrote: > Hello everybody, > I would like to know as to how I would write the following code in a > more idiomatic way. > > (let [mp (atom {}) > d [#{#{1 2} > #{3 4}} ;node1 > #{#{5 6} > #{7 8}} ;node2]] > (dorun (for [nd d nd-pair nd face nd-pair] > (swap! mp update-in [face] #(conj % nd > @mp) > > ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 > form node2 > ;I would like a map in the opposite direction .. > ;i.e. I should be able to find out all the nodes of which 1 is part of and > ;that is what the above code is doing.. but would like to know as to what > ;would be a more idiomatic way of doing this. > > https://gist.github.com/726773 > > I don't like the fact that I am using atom and swap .. can anybody > suggest a better way to do it? > > Thanks, > Sunil. -- 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: more idiomatic clojure
Thanks Laurent.. That really helps and also thanks for the tip of how to try to do it in general. Sunil. On Fri, Dec 3, 2010 at 3:48 PM, Laurent PETIT wrote: > Hello, > > one way: > > (apply > merge-with > conj > {} > (for [nd d nd-pair nd face nd-pair] > {face nd})) > > The idea is (as is generally the case for me when trying to move from > imperative code to functional), is to try not to do too many things in a > single step. > So here, first I extract from the "for" "pieces of information", individual > pairs of face => containing-node into an intermediate sequence. > Then I consume this sequence with merge-with. > I could also consume this sequence with reduce, of course: > (reduce (fn [m fnd] (merge-with conj m fnd) (for ...)) > > > HTH, > > -- > Laurent > > > 2010/12/3 Sunil S Nandihalli > >> Hello everybody, >> >> I would like to know as to how I would write the following code in a more >> idiomatic way. >> >> >> >> >> >> >> >> (let [mp (atom {}) >> >> >> >> >> d [#{#{1 2} >> >> >> >> >>#{3 4}} ;node1 >> >> >> >> >> #{#{5 6} >> >> >> >> >>#{7 8}} ;node2]] >> >> >> >> >> (dorun (for [nd d nd-pair nd face nd-pair] >> >> >> >> >>(swap! mp update-in [face] #(conj % nd >> >> >> >> >> @mp) >> >> >> >> >> >> >> ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 form >> node2 >> >> >> >> >> ;I would like a map in the opposite direction .. >> >> >> >> >> ;i.e. I should be able to find out all the nodes of which 1 is part of and >> >> >> >> >> ;that is what the above code is doing.. but would like to know as to what >> >> >> >> >> ;would be a more idiomatic way of doing this. >> >> >> >> >> >> >> >> https://gist.github.com/726773 >> >> >> >> >> I don't like the fact that I am using atom and swap .. can anybody suggest a >> better way to do it? >> >> >> >> Thanks, >> Sunil. >> >> -- >> 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 > > > -- > 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 -- 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: more idiomatic clojure
Hello, one way: (apply merge-with conj {} (for [nd d nd-pair nd face nd-pair] {face nd})) The idea is (as is generally the case for me when trying to move from imperative code to functional), is to try not to do too many things in a single step. So here, first I extract from the "for" "pieces of information", individual pairs of face => containing-node into an intermediate sequence. Then I consume this sequence with merge-with. I could also consume this sequence with reduce, of course: (reduce (fn [m fnd] (merge-with conj m fnd) (for ...)) HTH, -- Laurent 2010/12/3 Sunil S Nandihalli > Hello everybody, > > I would like to know as to how I would write the following code in a more > idiomatic way. > > > > > > (let [mp (atom {}) > > > d [#{#{1 2} > > >#{3 4}} ;node1 > > > #{#{5 6} > > >#{7 8}} ;node2]] > > > (dorun (for [nd d nd-pair nd face nd-pair] > > >(swap! mp update-in [face] #(conj % nd > > > @mp) > > > > > ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 form > node2 > > > ;I would like a map in the opposite direction .. > > > ;i.e. I should be able to find out all the nodes of which 1 is part of and > > > ;that is what the above code is doing.. but would like to know as to what > > > ;would be a more idiomatic way of doing this. > > > > > > https://gist.github.com/726773 > > > > > I don't like the fact that I am using atom and swap .. can anybody suggest a > better way to do it? > > > > Thanks, > Sunil. > > -- > 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 -- 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
more idiomatic clojure
Hello everybody, I would like to know as to how I would write the following code in a more idiomatic way. (let [mp (atom {}) d [#{#{1 2} #{3 4}} ;node1 #{#{5 6} #{7 8}} ;node2]] (dorun (for [nd d nd-pair nd face nd-pair] (swap! mp update-in [face] #(conj % nd @mp) ; if you consider that points 1 2 3 4 form the node node1 and 5 6 7 8 form node2 ;I would like a map in the opposite direction .. ;i.e. I should be able to find out all the nodes of which 1 is part of and ;that is what the above code is doing.. but would like to know as to what ;would be a more idiomatic way of doing this. https://gist.github.com/726773 I don't like the fact that I am using atom and swap .. can anybody suggest a better way to do it? Thanks, Sunil. -- 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