Re: partition-starting-every : yet another partition function

2010-09-16 Thread Thomas
I agree with number 2: it would be very nice to have this in contrib. I needed it last month and rolled my own (less clean) version. Thomas On Sep 10, 10:26 pm, Matt Smith wrote: > problem: convert a collection [1 2 0 1 2 3 0 1 2 3 0 0 1 2] into > partitions like: > ((1 2) (0 1 2 3) (0 1 2 3) (

Re: partition-starting-every : yet another partition function

2010-09-16 Thread Christophe Grand
On Thu, Sep 16, 2010 at 10:45 PM, Chouser wrote: > On Fri, Sep 10, 2010 at 4:26 PM, Matt Smith wrote: > > problem: convert a collection [1 2 0 1 2 3 0 1 2 3 0 0 1 2] into > > partitions like: > > ((1 2) (0 1 2 3) (0 1 2 3) (0) (0 1 2)) > > In this case, start each partition on a 0. > > Iteratio

Re: practical clojure

2010-09-16 Thread Stuart Sierra
Thanks! Glad you liked the book. -S On Sep 14, 8:37 am, faenvie wrote: > i just emerged from a whirlwind read > through 'practical clojure'. i like this book > very much. > > it's a very well structured, carefully written > book. kind of a minimalistic approach but minimalistic > in the positive

Re: partition-starting-every : yet another partition function

2010-09-16 Thread Chouser
On Fri, Sep 10, 2010 at 4:26 PM, Matt Smith wrote: > problem: convert a collection [1 2 0 1 2 3 0 1 2 3 0 0 1 2] into > partitions like: > ((1 2) (0 1 2 3) (0 1 2 3) (0) (0 1 2)) > In this case, start each partition on a 0. > > > I looked at the various partition functions but none of them would

Re: simplest graphics?

2010-09-16 Thread Lee Spector
On Sep 16, 2010, at 12:13 PM, Alan wrote: > I think you may have misunderstood the first suggestion I made, about > keeping (shape, color) pairs in your atomic vector. I really meant > java.awt.Shape and java.awt.Color objects, rather than a symbol > (keyword is better as Christophe suggests) and a

Re: simplest graphics?

2010-09-16 Thread Alan
I think you may have misunderstood the first suggestion I made, about keeping (shape, color) pairs in your atomic vector. I really meant java.awt.Shape and java.awt.Color objects, rather than a symbol (keyword is better as Christophe suggests) and a bunch of numbers. Like so: (defn render-shape [g

Re: thinking in clojure

2010-09-16 Thread Btsai
That pattern will be a great addition to the toolbox, thank you :) On Sep 16, 9:58 am, Laurent PETIT wrote: > And note that the pattern works at any level, and is easily readable, since > update-in "flattens" the arguments of the modifying function : > > If you want to "touch" the path [:a :b :c

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
And note that the pattern works at any level, and is easily readable, since update-in "flattens" the arguments of the modifying function : If you want to "touch" the path [:a :b :c :d] and provide specific default values at each level if the key is not found, it's as "simple" as : (update-in coll

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
So nested calls to update-in are needed in order to be able to provide a specific default value, everytime just having an empty map created isn't sufficient. So instead of (update-in {} [:a :b] identity) which returns {:a {:b nil}} , you can break the key path at :a so that the default value if no

Re: missing queue function in core?

2010-09-16 Thread nickikt
I thought it was odd too so I think something that makes this easier would be good. On Sep 15, 9:00 pm, grignaak wrote: > Does it seem odd to anyone else that this function is missing in core? > I propose it gets added. > > (defn queue >  ([] clojure.lang.PersistentQueue/EMPTY ) >  ([x] (conj (qu

Re: thinking in clojure

2010-09-16 Thread Btsai
My poor brain can't handle nested calls to update-in, so this is what I came up with: (defn add-meetings [data k meetings] (cond (nil? (data k)) (assoc data k {:title "title" :meetings meetings}) :else (update-in data [k :meetings] concat meetings))) On Sep 16, 8:53 am, Laurent PETIT wro

Re: Talk at QCon SP

2010-09-16 Thread Vivek Khurana
On Sep 14, 3:49 am, Pedro Teixeira wrote: > Last night, I had the chance to talk about some of the technologies > I've put together in a recent project. > In particular, it's about mixing clojure + cqrs + event sourcing + > cep. > > I made slides available athttp://tinyurl.com/pedroqcon-- and I'

Re: missing queue function in core?

2010-09-16 Thread Sean Devlin
+1 On Sep 15, 3:00 pm, grignaak wrote: > Does it seem odd to anyone else that this function is missing in core? > I propose it gets added. > > (defn queue >  ([] clojure.lang.PersistentQueue/EMPTY ) >  ([x] (conj (queue) x)) >  ([x y] (conj (queue x) y)) >  ([x y & more] (into (queue x y) more)))

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
2010/9/16 Meikel Brandmeyer > Hi Laurent, > > On 16 Sep., 15:54, Laurent PETIT wrote: > > > you don't like my one-liner ? :-) > > I saw your message only after I sent mine. :) > > > (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp > vec > > concat) data) > > Hmm... (comp ve

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi Laurent, On 16 Sep., 15:54, Laurent PETIT wrote: > you don't like my one-liner ? :-) I saw your message only after I sent mine. :) > (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec > concat) data) Hmm... (comp vec concat) == into? Meikel -- You received this m

Re: partition-starting-every : yet another partition function

2010-09-16 Thread Nicolas Oury
I think that unfold (or co-reduce, or generate) should find its way in contrib. I am not sure we need finished arg though. The traditional finish in the seq family is nil. My own version of unfold: (defn unfold "(unfold seed grow) use the seed and a function grow that returns an element and an

Re: Feature idea: meta-macros

2010-09-16 Thread Nicolas Oury
The logged function would have to be already a generic method, no? On Wed, Sep 15, 2010 at 7:50 PM, Matt Fowles wrote: > All~ > My clojure is fairly weak, but the particular example given would be > accomplished in common lisp using generic methods and the >  :around modifier... > http://www.aiai

Re: inline vs extended types

2010-09-16 Thread Meikel Brandmeyer
Hi, On 15 Sep., 12:55, SIdhant Godiwala wrote: > Is there any way to define the MultiMap protocol inline with the > clashing methods? How could there be one? The compiler cannot decide which method to call. Although their name is the same the could have completely different meaning for the diff

Re: ClassCastException: class to interface

2010-09-16 Thread Michael Wood
On 15 September 2010 05:31, JonnyB wrote: > Thank you very much, for your quick reply! At least, i can be sure > now, that in principle it should be working. > > What i wanna do is wrap the jMonkeyEngine3. > The hello world example (http://jmonkeyengine.org/wiki/doku.php/ > jme3:beginner:hello_sim

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
Hi Meikel, you don't like my one-liner ? :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec concat) data) 2010/9/16 Meikel Brandmeyer > Hi, > > On 16 Sep., 15:36, Meikel Brandmeyer wrote: > > > > (if (not (nil? (next collection) > > > > You can save the nil?. (if

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi, On 16 Sep., 15:36, Meikel Brandmeyer wrote: > >   (if (not (nil? (next collection) > > You can save the nil?. (if (not (next collection))) will also work. > nil is logically false. And of course this should be (if (next collection)). The not belongs to the "You can save" part. Sincerely Me

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi, maybe this does what you want. I'm not sure, since you add the new meeting to *all* meetings? And where does the :title come from when you add a new meeting? I assume you have a map of a meeting title and a meeting and want to add this to the corresponding entry in the data map. If the meeting

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
Something along those lines : (def t { 0 {:title "some" :meetings [ :d1 ]} 2 {:title "some2" :meetings [ :d2 ]}}) user=> (pprint (update-in t [1] (fnil update-in {:title "title" :meetings []}) [:meetings] (comp vec concat) [:d1 :d2]int (update-in t [1] (fnil update-in {:title "title" :meetings []

Re: thinking in clojure

2010-09-16 Thread Mike Meyer
On Wed, 15 Sep 2010 11:48:09 -0700 Michael Ossareh wrote: > Hi Guys, > > One of the things that has struck me about clojure, by virtue of being > a lisp, is the concision of the code - I really find it very > attractive. However yesterday I found something that I couldn't work > out how to do in

Re: thinking in clojure

2010-09-16 Thread David Nolen
On Wed, Sep 15, 2010 at 2:48 PM, Michael Ossareh wrote: > Hi Guys, > > One of the things that has struck me about clojure, by virtue of being > a lisp, is the concision of the code - I really find it very > attractive. However yesterday I found something that I couldn't work > out how to do in a

missing queue function in core?

2010-09-16 Thread grignaak
Does it seem odd to anyone else that this function is missing in core? I propose it gets added. (defn queue ([] clojure.lang.PersistentQueue/EMPTY ) ([x] (conj (queue) x)) ([x y] (conj (queue x) y)) ([x y & more] (into (queue x y) more))) Also, to get a good string representation in the repl,

Re: Feature idea: meta-macros

2010-09-16 Thread Matt Fowles
All~ My clojure is fairly weak, but the particular example given would be accomplished in common lisp using generic methods and the :around modifier... http://www.aiai.ed.ac.uk/~jeff/clos-guide.html Matt On Wed, Sep 15, 2010 at 2:26 PM, Alan wr

thinking in clojure

2010-09-16 Thread Michael Ossareh
Hi Guys, One of the things that has struck me about clojure, by virtue of being a lisp, is the concision of the code - I really find it very attractive. However yesterday I found something that I couldn't work out how to do in a concise manner. Clearly commenting the code was a priority once I got

Re: partition-starting-every : yet another partition function

2010-09-16 Thread Gijs S.
This answers neither question 1 nor 2, but there is a function from the map, filter and reduce family of higher order functions that is applicable to this problem. The function is called unfold and is the opposite of reduce (see http://en.wikipedia.org/wiki/Anamorphism). "An unfold builds a (poten

inline vs extended types

2010-09-16 Thread SIdhant Godiwala
Hey guys, I'm having some issues with defining types using deftype and would really appreciate some help. Inspired by Mark Engelberg's PersistentPriorityMap http://github.com/clojure/clojure-contrib/blob/master/modules/priority-map/src/main/clojure/clojure/contrib/priority_map.clj, I decided

Re: ClassCastException: class to interface

2010-09-16 Thread JonnyB
Thank you very much, for your quick reply! At least, i can be sure now, that in principle it should be working. What i wanna do is wrap the jMonkeyEngine3. The hello world example (http://jmonkeyengine.org/wiki/doku.php/ jme3:beginner:hello_simpleapplication) works fine (code below). But when i a

Re: why doesn't a function have a type ?

2010-09-16 Thread Thierry Pirot
Belun writes: > why isn't the type of a function : clojure.lang.IFn ? > it's this instead : > user=> (type #(str "wonder" "what" "this" "is")) > user$eval7$fn__8 user> (class #(str "wonder" "what" "this" "is")) user$eval3515$fn__3516 user> (pprint1 (ancestors *1)) #{clojure.lang.Fn clojure.lang.

Re: logging

2010-09-16 Thread lprefontaine
We use common logging with a thin Clojure layer around it. It allows us to have different behaviors in dev pre-prod and production. We avoid the hassle of configuring log4j in dev. The default implementation (simple logging) is more than enough most of the time. In prod, we specify the log4j confi

Re: simplest graphics?

2010-09-16 Thread Christophe Grand
Hi Lee, On Thu, Sep 16, 2010 at 5:15 AM, Lee Spector wrote: > Also, this would have a smaller impact but I'm curious about it: is there a > way to treat method names as data and then make calls to them, as one can > with clojure functions? Then I could pass things like fillRect, or map rect > to

Re: simplest graphics?

2010-09-16 Thread Michael Gardner
On Sep 15, 2010, at 10:15 PM, Lee Spector wrote: > Also, this would have a smaller impact but I'm curious about it: is there a > way to treat method names as data and then make calls to them, as one can > with clojure functions? Then I could pass things like fillRect, or map rect > to fillRect,

Re: Feature idea: meta-macros

2010-09-16 Thread Laurent PETIT
2010/9/16 Christophe Grand > Hi, > > > On Wed, Sep 15, 2010 at 8:52 PM, Luke VanderHart < > luke.vanderh...@gmail.com> wrote: > >> Oh, you're right, of course. >> >> Still, that doesn't quite meet the case I described, since the >> bindings won't effect any spawned threads/agents. >> > > (alter-v

Re: Feature idea: meta-macros

2010-09-16 Thread Christophe Grand
Hi, On Wed, Sep 15, 2010 at 8:52 PM, Luke VanderHart wrote: > Oh, you're right, of course. > > Still, that doesn't quite meet the case I described, since the > bindings won't effect any spawned threads/agents. > (alter-var-root #'sql log-around) then -- You received this message because you ar