Re: Queues in Clojure

2010-12-03 Thread Rasmus Svensson
2010/12/3 Andreas Kostler andreas.koestler.le...@gmail.com: 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

Re: Tailing a file in Clojure

2010-12-03 Thread Alex Osborne
patrickdlogan patrickdlo...@gmail.com 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

Creating map from string

2010-12-03 Thread 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? Thanks. -- You received this message because you are

Re: Wolfram: 100 years since Principia Mathematica

2010-12-03 Thread Alec Battles
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

Re: Creating map from string

2010-12-03 Thread Laurent PETIT
Hi, 2010/12/3 Anclj anb...@gmail.com 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

Re: Creating map from string

2010-12-03 Thread Sunil S Nandihalli
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 anb...@gmail.com wrote: Hi, I have a

Re: Creating map from string

2010-12-03 Thread Laurent PETIT
2010/12/3 Laurent PETIT laurent.pe...@gmail.com Hi, 2010/12/3 Anclj anb...@gmail.com 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,

Re: more idiomatic clojure

2010-12-03 Thread Sunil S Nandihalli
thanks Rayne. On Fri, Dec 3, 2010 at 4:02 PM, Rayne disciplera...@gmail.com 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

outlining for clojure files in emacs+slime?

2010-12-03 Thread Sunil S Nandihalli
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

Re: implementing nth for sorted-set and sorted-map

2010-12-03 Thread Ken Wesson
On Fri, Dec 3, 2010 at 2:27 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com 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

Re: Creating map from string

2010-12-03 Thread Ken Wesson
On Fri, Dec 3, 2010 at 10:08 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/12/3 Laurent PETIT laurent.pe...@gmail.com 2010/12/3 Anclj anb...@gmail.com 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?

Re: more idiomatic clojure

2010-12-03 Thread Ken Wesson
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

Re: Tailing a file in Clojure

2010-12-03 Thread Stuart Sierra
On Dec 2, 10:55 pm, patrickdlogan patrickdlo...@gmail.com 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

Re: Creating map from string

2010-12-03 Thread Laurent PETIT
2010/12/3 Ken Wesson kwess...@gmail.com On Fri, Dec 3, 2010 at 10:08 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/12/3 Laurent PETIT laurent.pe...@gmail.com 2010/12/3 Anclj anb...@gmail.com I've got: user (split (slurp data) #,) [0 2 1 5 2 8 3 15 4 9] And I would like:

Re: Tailing a file in Clojure

2010-12-03 Thread Alex Miller
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

Re: Creating map from string

2010-12-03 Thread Ken Wesson
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

Re: more idiomatic clojure

2010-12-03 Thread 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

Re: more idiomatic clojure

2010-12-03 Thread Laurent PETIT
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 cloj...@blackbirdsystems.net (apply merge-with conj {} (for [nd d nd-pair nd face nd-pair]

Re: Creating map from string

2010-12-03 Thread Laurent PETIT
2010/12/3 Ken Wesson kwess...@gmail.com 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

Re: more idiomatic clojure

2010-12-03 Thread George Jahad
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 

Quene in Clojure

2010-12-03 Thread 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

Re: Quene in Clojure

2010-12-03 Thread patrickdlogan
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 andreas.koestler.le...@gmail.com wrote: Hi All, May I cite an Author of a

Re: Tailing a file in Clojure

2010-12-03 Thread patrickdlogan
On Dec 3, 4:42 am, Alex Osborne a...@meshy.org wrote: patrickdlogan patrickdlo...@gmail.com 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

Easy Way To Download Clojure Libraries From Git

2010-12-03 Thread Asim Jalis
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:

Re: Easy Way To Download Clojure Libraries From Git

2010-12-03 Thread Sunil S Nandihalli
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

Re: dosync style

2010-12-03 Thread ka
(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

Re: Easy Way To Download Clojure Libraries From Git

2010-12-03 Thread buckmeisterq
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

Re: Easy Way To Download Clojure Libraries From Git

2010-12-03 Thread Alan Dipert
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, buckmeist...@gmail.com wrote: I second the recommendation to use leiningen. I

Re: why not change type compare functions do a compare on strings as well?

2010-12-03 Thread ka
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

Re: when to use io! macro?

2010-12-03 Thread ka
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 alexander.barano...@gmail.com wrote: Hi guys, I've

what does the value part of env map automatically passed to all macros contain?

2010-12-03 Thread Sunil S Nandihalli
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

Re: dosync style

2010-12-03 Thread James Reeves
On 29 November 2010 16:33, Stuart Halloway stuart.hallo...@gmail.com 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

Re: when to use io! macro?

2010-12-03 Thread Sunil S Nandihalli
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

Re: when to use io! macro?

2010-12-03 Thread Sunil S Nandihalli
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

Re: functional thinking

2010-12-03 Thread ka
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

Re: resultset-seq improvement: mapping column names

2010-12-03 Thread ka
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

Re: what does the value part of env map automatically passed to all macros contain?

2010-12-03 Thread Alex Osborne
Sunil S Nandihalli sunil.nandiha...@gmail.com 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

Re: why not change type compare functions do a compare on strings as well?

2010-12-03 Thread Tim Robinson
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

Re: what does the value part of env map automatically passed to all macros contain?

2010-12-03 Thread Sunil S Nandihalli
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 a...@meshy.org wrote: Sunil S Nandihalli sunil.nandiha...@gmail.com

Re: what does the value part of env map automatically passed to all macros contain?

2010-12-03 Thread Sunil S Nandihalli
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 a...@meshy.org wrote: Sunil S Nandihalli

Re: Easy Way To Download Clojure Libraries From Git

2010-12-03 Thread Asim Jalis
Thanks! This is exactly what I was looking for. On Fri, Dec 3, 2010 at 6:12 PM, Alan Dipert a...@dipert.org 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.

more idiomatic clojure

2010-12-03 Thread 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

Re: more idiomatic clojure

2010-12-03 Thread Laurent PETIT
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

Re: more idiomatic clojure

2010-12-03 Thread Rayne
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 sunil.nandiha...@gmail.com wrote: Hello everybody,  

Queues in Clojure

2010-12-03 Thread 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

Re: Tailing a file in Clojure

2010-12-03 Thread Saul Hazledine
On Dec 2, 8:53 am, viksit vik...@gmail.com 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