a question about using the delay macro

2011-08-22 Thread faenvie
hi clojure-community, yesterday i came across the following use of the delay-macro: (defn pooled-data-source [db-connection-settings] ; this Fn creates and returns object of type PooledDataSource ) (defn pooled-data-source-as-singleton [db-connection-settings] (let [datasource (delay (po

Re: a question about using the delay macro

2011-08-22 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 22. August 2011 11:53:32 UTC+2 schrieb faenvie: > > yesterday i came across the following use of > the delay-macro: > > (defn pooled-data-source > [db-connection-settings] > ; this Fn creates and returns object of type PooledDataSource > ) > > (defn pooled-data-source-as-s

Problem in downloading StringTemplate using lein deps.

2011-08-22 Thread mmwaikar
Hi, There is no jar available for StringTemplate in clojars. But StringTemplate v3.2 jar is available in Maven. So I included the necessary entry for StringTemplate in project.clj and tried downloading using lein deps. It gives me the below error - Downloading: stringtemplate/stringtemplate/3.

Re: Video & Slides on Pattern Matching and Predicate Dispatch in Clojure

2011-08-22 Thread Brent Millare
The alternative to using eval and large code generation that I've seen is to use the compiled tree of closures approach used by CL-PPCRE. If the JVM is smart enough, it may do the inlining for you on the hot code. http://en.wikibooks.org/wiki/Common_Lisp/External_libraries/CL-PPCRE#Regular_Express

Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Laurent PETIT
Hi, I was curious to see Marginalia in action, but was then surprised to see a lot of code like this: ;; Produce a total score as the sum of the points awarded during each round. (defn total [strategy] (reduce + (:points strategy))) That is, no more docstring, which is replaced in favor of a

Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Dave Ray
I'm not sure why this code was written this way, but Marginalia has no problem using docstrings. Compare it's own docs: http://fogus.me/fun/marginalia/ and the code they were generated from: https://github.com/fogus/marginalia/blob/master/src/marginalia/core.clj Cheers, Dave On Mon, Aug 2

Re: Problem in downloading StringTemplate using lein deps.

2011-08-22 Thread Mark Rathwell
Stringtemplate is [org.antlr/Stringtemplate "3.2"]. Clojure libraries are generally available in Clojars, open source Java libraries are often available in Maven Central. The lein project.clj dependency format is [goupId/artifactId "version"], from the maven pom format: org.antlr string

Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Laurent PETIT
2011/8/22 Dave Ray > I'm not sure why this code was written this way, but Marginalia has no > problem using docstrings. Compare it's own docs: > > http://fogus.me/fun/marginalia/ > > and the code they were generated from: > > https://github.com/fogus/marginalia/blob/master/src/marginalia/core.c

Apply concat and mapcat evaluate seqs unnecessarily

2011-08-22 Thread Asim Jalis
user=> (defn f [[x]] (println "computing x:" (inc x)) (vector (inc x))) #'user/f user=> (->> (iterate f [0]) (take 0)) () user=> (->> (iterate f [0]) (apply concat) (take 0)) computing x: 1 computing x: 2 computing x: 3 () user=> (->> (iterate f [0]) (mapcat identity) (take 0)) computing x: 1 compu

Generating new exception classes in clojure

2011-08-22 Thread Brian Hurt
OK, I'm not sure if I'm just missing something obvious here, or if there really is no way to do this. What I want to be able to do is to be able to create new exception classes, in the repl, and be able to throw them and catch them. What I want to be able to do is something like: (defexception m

Aw: Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Stefan Kamphausen
Hi, Am Montag, 22. August 2011 16:08:20 UTC+2 schrieb lpetit: > > 2011/8/22 Dave Ray > >> I'm not sure why this code was written this way, but Marginalia has no >> problem using docstrings. Compare it's own docs: >> [...] > > ok, thanks Dave > that Marginalia also understands docstrings notwith

Re: a question about using the delay macro

2011-08-22 Thread Luc Prefontaine
Or you could use Boing to create your data source and hide most of that wiring away from your code. I am doing a sales pitch here for my own stuff :))) https://github.com/lprefontaine/Boing/blob/master/examples/spring-1-to-boing.clj Luc P. On Mon, 22 Aug 2011 03:04:29 -0700 (PDT) "Meikel Brandm

Re: Clojure Speed performance test

2011-08-22 Thread artg
Below is a Clojure solution that runs in 8.58 microseconds on my machine. I only did it for the 40, 3 case. Records are linked. The list reduction solution runs in 23.4 and the element recursion in 27.3 --art (defrecord Soldier [val r]) (def v (vec (map #(Soldier. % (inc %)) (range 40 (def v2

Re: Apply concat and mapcat evaluate seqs unnecessarily

2011-08-22 Thread Meikel Brandmeyer
Hi, Am 22.08.2011 um 16:32 schrieb Asim Jalis: > Is there a way to rewrite mapcat (or apply concat) so that they don't > evaluate the incoming seq unnecessarily? user=> (defn f [[x]] (println "Computing x:" x) [(inc x)]) #'user/f user=> (defn lazy-mapcat [f coll] (lazy-seq (when-let [s (

Re: Apply concat and mapcat evaluate seqs unnecessarily

2011-08-22 Thread Benny Tsai
This is my attempt to take Meikel's code and extend it to accept arbitrarily many collections as 'mapcat' does: (defn lazy-mapcat [f & colls] (lazy-seq (when (every? seq colls) (concat (apply f (map first colls)) (apply lazy-mapcat f (map rest colls)) user=> (->> (iter

Re: Apply concat and mapcat evaluate seqs unnecessarily

2011-08-22 Thread Asim Jalis
Nice. Are there any technical reasons this isn't the default implementation of mapcat in Clojure.core? On Mon, Aug 22, 2011 at 9:27 AM, Meikel Brandmeyer wrote: > Hi, > > Am 22.08.2011 um 16:32 schrieb Asim Jalis: > >> Is there a way to rewrite mapcat (or apply concat) so that they don't >> evalu

Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Christian Romney
On Aug 22, 10:04 am, Dave Ray wrote: > I'm not sure why this code was written this way, but Marginalia has no > problem using docstrings. Compare it's own docs: > Chalk it up to noob mistake... :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Re: Prisoner's Dilemma in Clojure

2011-08-22 Thread Christian Romney
On Aug 21, 9:57 pm, Base wrote: > Very very nice! > Thanks for the encouragement! I should publicly thank Alan Malloy as well, who took the trouble to submit a patch improving some rather unidiomatic code. Thanks to all who have looked at it–I really appreciate the feedback. I'm really excited

Re: Video & Slides on Pattern Matching and Predicate Dispatch in Clojure

2011-08-22 Thread Brent Millare
> For pattern matching code size is a one time cost. For predicate dispatch, > that's a lot of code to generated, since every new predicate case will > produce an entirely new tree. But perhaps people won't care that much. Only > time and experience reports will tell. If you want, you can be lazy

Re: Video & Slides on Pattern Matching and Predicate Dispatch in Clojure

2011-08-22 Thread Brent Millare
Actually to simply further, instead of wrapping the old DAG tree, it simply replaces the DAG tree with the compilation step. The compilation step then makes the new DAG tree and calls it. On Aug 22, 3:07 pm, Brent Millare wrote: > > For pattern matching code size is a one time cost. For predicate

Re: Video & Slides on Pattern Matching and Predicate Dispatch in Clojure

2011-08-22 Thread David Nolen
On Mon, Aug 22, 2011 at 3:07 PM, Brent Millare wrote: > > For pattern matching code size is a one time cost. For predicate > dispatch, > > that's a lot of code to generated, since every new predicate case will > > produce an entirely new tree. But perhaps people won't care that much. > Only > > ti

Re: Generating new exception classes in clojure

2011-08-22 Thread David Powell
You can use proxy for this. It doesn't create wrappers, it creates a proper subclass with methods that delegate to clojure functions via var lookup. -- Dave -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojur

Re: Generating new exception classes in clojure

2011-08-22 Thread Brian Hurt
How can I catch a proxied Throwable class without catching everything? I suppose I could grab the class and go at it with reflection... Brian On Mon, Aug 22, 2011 at 3:21 PM, David Powell wrote: > You can use proxy for this. It doesn't create wrappers, it creates a > proper subclass with meth

Re: Generating new exception classes in clojure

2011-08-22 Thread Craig Andera
> How can I catch a proxied Throwable class without catching everything?  I > suppose I could grab the class and go at it with reflection... I wrestled with this problem for a while, and got to "you can't do it". At least, not without AOT compilation of some sort. I did come up with a horrible, ho

Re: Generating new exception classes in clojure

2011-08-22 Thread Phil Hagelberg
On Mon, Aug 22, 2011 at 11:02 AM, Brian Hurt wrote: > What I want to be able to do is to be able to create new exception classes, > in the repl, and be able to throw them and catch them. At the risk of sounding curmudgeonly: are you sure that's what you want? I suspect you really just want to be

Re: Clojure Speed performance test

2011-08-22 Thread Isaac Gouy
On Aug 18, 6:50 am, David Nolen wrote: > The Clojure code posted there is pretty awful and shows a gross, gross > misunderstanding of Clojure data types. I submitted one improved version > already, but didn't spend the time to make it really, really fast. > > For this particular kind of pointles

Re: Clojure Speed performance test

2011-08-22 Thread Isaac Gouy
On Aug 18, 7:34 am, Michael Jaaka wrote: > For list reduction it is said to remove every third solder but just > with 1 step they remove 1 soldier. There is something wrong Scully. The author knows, and says that "variant" seemed more interesting. (It should be easy enough to factor out the d