Re: commute documentation detail

2009-08-03 Thread Christophe Grand
I think Mark's code exhibits a bug: (def my-ref (ref 1)) (dosync (ref-set my-ref 5) (commute my-ref inc)) ; returns 6 (println "my-ref =" @my-ref) ; prints 7 since my-ref is ref-set, my-ref is in LockingTransaction/sets but its current value in LockingTransaction/vals is set by commute to 6

Question about pmap

2009-08-03 Thread Johann Kraus
Hi all, recently I did some micro-benchmarks of parallel code on my 8-core computer. But I don't get the point about this behaviour of pmap. Can anyone explain this to me? The code is running on a dual quad-core intel machine (Xeon X5482, 3.20 GHz). (defn maptest [cores] (doall (map (fn [x] (dot

Re: Question about pmap

2009-08-03 Thread Johann Kraus
Sorry about the copy&paste error. I partially changed len to cores. The code must look like: (defn maptest [cores] (doall (map (fn [x] (dotimes [_ 10] (inc 0))) (range cores (defn pmaptest [cores] (doall (pmap (fn [x] (dotimes [_ 10] (inc 0))) (range cores and (defn mapt

Memfn: what does it mean?

2009-08-03 Thread Garth Sheldon-Coulson
Out of curiosity, does anyone know what memfn stands for? Is it an abbreviation? Fn obviously stands for function. Mem calls to mind memoize, but I'm not sure I see how memfn memoizes anything... --~--~-~--~~~---~--~~ You received this message because you are subscr

Newbie question on using Java Libraries

2009-08-03 Thread Adie
Good Afternoon folks, I am a newbie to Clojure, coming from CL, with very little Java background. I am trying to use the 'javax.persistence' libraries, but i just cant seem to import it properly for e.g (import '(javax.persistence Persistence) gives a java.lang.ClassNotFoundException: javax.pers

The :while modifier (list comprehensions)

2009-08-03 Thread Jonas
I find the :while modifier non intuitive user=> (for [x (range 1 10) y (range 1 10) :while (= y 2)] [x y]) () user=> (for [x (range 1 10) y (range 1 10) :while (= x 2)] [x y]) ([2 1] [2 2] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9]) My (false) intuition told me that both expressions would have be

Re: Trampolined backtracking maze solver

2009-08-03 Thread James Sofra
Thanks John! Those suggestions are really helpful, the short- circuiting 'and' is good to remember. > Might simplify this a bit using assoc-in. Yeah this works, nice, thanks. (defn update-tile [[x y] maze value] (if (tile-in-bounds? [x y] maze) (assoc-in maze [y x] value) maze)) Chee

Re: Memfn: what does it mean?

2009-08-03 Thread Mike DeLaurentis
I believe it stands for "member function". From the doc string: "Expands into code that creates a fn that expects to be passed an object and any args and calls the named instance method on the object passing the args. Use when you want to treat a Java method as a first-class fn." On Mon,

Re: The :while modifier (list comprehensions)

2009-08-03 Thread Chouser
On Mon, Aug 3, 2009 at 2:47 AM, Jonas wrote: > > I find the :while modifier non intuitive > > user=> (for [x (range 1 10) y (range 1 10) :while (= y 2)] [x y]) > () > user=> (for [x (range 1 10) y (range 1 10) :while (= x 2)] [x y]) > ([2 1] [2 2] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9]) > > My

Re: The :while modifier (list comprehensions)

2009-08-03 Thread Meikel Brandmeyer
Hi, On Aug 3, 8:47 am, Jonas wrote: > I find the :while modifier non intuitive > > user=> (for [x (range 1 10) y (range 1 10) :while (= y 2)] [x y]) > () > user=> (for [x (range 1 10) y (range 1 10) :while (= x 2)] [x y]) > ([2 1] [2 2] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9]) > > My (false) i

Re: Trampolined backtracking maze solver

2009-08-03 Thread Aaron Cohen
On Sun, Aug 2, 2009 at 3:28 PM, John Harrop wrote: > On Sun, Aug 2, 2009 at 5:48 AM, James Sofra wrote: > >> >> (defn get-tile [[x y] maze] >> (if (tile-in-bounds? [x y] maze) >>((maze y) x))) > > > (defn get-tile [[x y] maze] > (get (get maze y) x)) > While you're at it, why not: (get-i

Re: commute documentation detail

2009-08-03 Thread Rich Hickey
On Mon, Aug 3, 2009 at 5:44 AM, Christophe Grand wrote: > I think Mark's code exhibits a bug: > > (def my-ref (ref 1)) > > (dosync >   (ref-set my-ref 5) >   (commute my-ref inc)) ; returns 6 > > (println "my-ref =" @my-ref) ; prints 7 > > since my-ref is ref-set, my-ref is in LockingTransaction/s

Re: Memfn: what does it mean?

2009-08-03 Thread Garth Sheldon-Coulson
Ah, makes sense. Thanks. On Mon, Aug 3, 2009 at 8:53 AM, Mike DeLaurentis wrote: > > I believe it stands for "member function". From the doc string: > > "Expands into code that creates a fn that expects to be passed an > object and any args and calls the named instance method on the > object p

Re: Newbie question on using Java Libraries

2009-08-03 Thread Meikel Brandmeyer
Hi, On Aug 3, 10:16 am, Adie wrote: > for e.g > (import '(javax.persistence Persistence) > gives a > java.lang.ClassNotFoundException: javax.persistence.Persistence > (NO_SOURCE_FILE:0) error > > How will i import javax.persistence properly? You have to name the Classes or Interfaces in the `i

Re: The :while modifier (list comprehensions)

2009-08-03 Thread Jonas Enlund
> When you put the :while at the `x` clause you get the expected empty > seq. > > user=> (for [x (range 1 10) :while (= x 2) y (range 1 10)] [x y]) > () Interesting, I didn't know that. Still, the behavior of :while feels strange. I guess I'll get used to it. In the following example :while and

Re: The :while modifier (list comprehensions)

2009-08-03 Thread Meikel Brandmeyer
Hi, Am 03.08.2009 um 16:56 schrieb Jonas Enlund: In the following example :while and :when are interchangeable, which is often the case when :while is used last in the list comprehension: user=> (for [x (range 1 10) y (range 1 10) :while (< (+ x y) 5)] [x y]) ([1 1] [1 2] [1 3] [2 1] [2 2]

Re: Question about pmap

2009-08-03 Thread tmountain
> However, the CPU usage indicated by "top" is ~690%. What does the CPU do? 100% per core. So with dual quad-core processors, it'd mean roughly 7 cores were being pegged. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Group

Re: Newbie question on using Java Libraries

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 4:16 AM, Adie wrote: > > Good Afternoon folks, > > I am a newbie to Clojure, coming from CL, with very little Java > background. > I am trying to use the 'javax.persistence' libraries, but i just cant > seem to import it properly > > for e.g > (import '(javax.persistence Pe

Re: Memfn: what does it mean?

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 8:53 AM, Mike DeLaurentis wrote: > > I believe it stands for "member function". From the doc string: > > "Expands into code that creates a fn that expects to be passed an > object and any args and calls the named instance method on the > object passing the args. Use when

Re: Memfn: what does it mean?

2009-08-03 Thread Richard Newman
> user=> (macroexpand-1 '(memfn add x y)) > (clojure.core/fn [target__4193__auto__ x y] (. target__4193__auto__ > (add x y))) > > That is, basically (fn [object x y] (.add object x y)). .add is macroexpanded into the more general dot form, as shown in the memfn expansion. user=> (read-string

Re: Question about pmap

2009-08-03 Thread Sudish Joseph
Johann Kraus writes: > Doing this with doubles: > leads to: > (time (maptest 8)) : 68044.060324 msecs > (time (pmaptest 8)) : 35051.174503 msecs > i.e. a speedup of ~2. > > However, the CPU usage indicated by "top" is ~690%. What does the CPU > do? My guess would be you're seeing the overhead

Re: Clojure without Rich Hickey

2009-08-03 Thread Luc Prefontaine
My two cents... Given that we committed to Clojure to get our product out in production, it's something we took into account when we decided to go forward with it. After all we did not want to change the core of our product in 5 years... :))) The way Clojure dev is handled presently is for us a p

Package manager proposal

2009-08-03 Thread James Reeves
Hi folks, I've been sketching out a design for a package manager for Clojure, similar to Rubygems. To the best of my knowledge, there's no real equivalent to this in Java-land. I'm looking for suggestions, criticisms, or for someone to tell me that Java already has a package manager that's bette

Re: Newbie question about peepcode server "Address already in use error"

2009-08-03 Thread Leotis buchanan
Nathan, I located the process, using nstat, and then I killed it,This worked, however this also killed my slime connection, which is bad, how can I release the address without killing the slime connection ? Leotis On Sun, Aug 2, 2009 at 10:11 AM, Nathan Lefler wrote: > Try either killing your

Re: Transient Data Structures

2009-08-03 Thread luke
Interesting. So I take it that these are (or should be) entirely a speed optimization? i.e, most the time, you'd want to write your code using the normal persistent data structures, and only go back and implement this within specific functions if they're a bottleneck? Sounds great. And for a som

Minor macro help

2009-08-03 Thread samppi
I'm trying to make a macro my-macro so that the last statement in: (def my-map {:a 2}) (defn process-a-map [arg] ...) ; Turns maps into corresponding vectors. ; (process-a-map my-map) returns ['*foo* :blah]. (my-macro a-map ; Last statement (do-something)) expands to: (bind

gen-struct: a Clojure macro for generating classes with mutable state

2009-08-03 Thread fyuryu
Hi, I modified the gen-struct macro a bit and got it to generate simple, mutable and immutable structures. You can customize only one aspect of those classes: their fields. Here's an example: (gen-struct :name my.test.struct :mutable-fields [[float x] [f

Re: Memfn: what does it mean?

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 3:45 PM, Richard Newman wrote: > > > user=> (macroexpand-1 '(memfn add x y)) > > (clojure.core/fn [target__4193__auto__ x y] (. target__4193__auto__ > > (add x y))) > > > > That is, basically (fn [object x y] (.add object x y)). > > .add is macroexpanded into the more gener

Re: Transient Data Structures

2009-08-03 Thread Vagif Verdi
On Aug 3, 1:52 pm, luke wrote: > So you could easily wrap an entirely functional code block > in a transform-to-transient macro that translates the functions to > their transient counterparts, and gain all the performance benefits? I do not think it would be that easy. Transient mode cannot be u

Re: Newbie question about peepcode server "Address already in use error"

2009-08-03 Thread Phil Hagelberg
Leotis buchanan writes: > I located the process, using nstat, and then I killed it,This worked, > however this also killed my slime connection, which is bad, how can I > release the address without killing the slime connection ? You are working on an earlier "step" of the mire codebase. In later

Re: Package manager proposal

2009-08-03 Thread Krešimir Šojat
Hi, There is Apache Ivy (http://ant.apache.org/ivy/) with it's Packager resolver that does exactly that (it has almost the same syntax as your proposal). For a repository using Apache Ivy + Package take a look at Ivy RoundUp (http://code.google.com/p/ivyroundup/), good thing about there desing i

Re: Transient Data Structures

2009-08-03 Thread Rich Hickey
On Aug 3, 5:52 pm, luke wrote: > Interesting. > > So I take it that these are (or should be) entirely a speed > optimization? i.e, most the time, you'd want to write your code using > the normal persistent data structures, and only go back and implement > this within specific functions if they'

Transient Data Structures

2009-08-03 Thread Rich Hickey
I've been doing some work on Transient Data Structures. You can read about them here: http://clojure.org/transients Feedback welcome, Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to

Re: Transient Data Structures

2009-08-03 Thread CuppoJava
Hi Rich, This is a very useful addition thanks. I personally find the O(1) transformation to and back most useful. I have a question about capturing the return values of conj! and assoc!. in this code: (let [v (transient []) v2 (conj! v 0)]) v2 is the captured return value from conj!, wh

Re: Minor macro help

2009-08-03 Thread CuppoJava
You can use eval to retrieve the value of a-map when the macro is expanded. (let [value (eval a-map)] `(binding ~(vec (process-a-map value)) ~...@forms)) I've programmed some substantial programs now in Clojure though, and I've never had to use this. Perhaps there is another way to achieve wha

Re: Transient Data Structures

2009-08-03 Thread Mark Engelberg
So if you want to make 10 changes to a vector, would it be worthwhile to turn it into a transient, make the 10 changes, and then turn it back to persistent? If no, then 100 changes? 1000? In other words, how much overhead is there in the transformation back and forth, and therefore, about how m

What happened to clojure.contrib web site ?

2009-08-03 Thread Vagif Verdi
There was this awesome browsable list of clojure libraries with short description of each, list of functions and even links to source. Now it all replaced with link to github. Please bring the user friendly and easily browsable documentation back! --~--~-~--~~~---~--

Re: What happened to clojure.contrib web site ?

2009-08-03 Thread Mike Hinchey
Do you mean this? http://clojure.org/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 moderat

Re: Transient Data Structures

2009-08-03 Thread Rich Hickey
On Aug 3, 7:27 pm, CuppoJava wrote: > Hi Rich, > This is a very useful addition thanks. I personally find the O(1) > transformation to and back most useful. > > I have a question about capturing the return values of conj! and > assoc!. > > in this code: > (let [v (transient []) >        v2 (con

Re: Transient Data Structures

2009-08-03 Thread Rich Hickey
On Aug 3, 8:06 pm, Mark Engelberg wrote: > So if you want to make 10 changes to a vector, would it be worthwhile > to turn it into a transient, make the 10 changes, and then turn it > back to persistent?  If no, then 100 changes?  1000? > > In other words, how much overhead is there in the tran

Re: Transient Data Structures

2009-08-03 Thread Mark Engelberg
On Mon, Aug 3, 2009 at 5:39 PM, Rich Hickey wrote: > In short, the O(1) overhead is less than the cost of even a single > edit. So, e.g. into/vec/vector now use transients unconditionally if > possible. Excellent. I'm glad to hear that the core functions will use transients so I don't have to ma

Re: Minor macro help

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 5:43 PM, samppi wrote: > I'm getting stuck because a-map always gets passed into my-macro > as a symbol. > > (defmacro my-macro [a-map & forms] ; Naive implementation >`(binding ~(vec (process-a-map a-map)) ~...@forms)) Try (defmacro my-macro [a-map & forms] ; Naive

Re: Transient Data Structures

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 7:27 PM, CuppoJava wrote: > > Hi Rich, > This is a very useful addition thanks. I personally find the O(1) > transformation to and back most useful. > > I have a question about capturing the return values of conj! and > assoc!. > > in this code: > (let [v (transient []) >

Re: Transient Data Structures

2009-08-03 Thread Andy Fingerhut
I like it. I can see significant use of these to help speed up some of the benchmark programs I've been hacking on: git://github.com/jafingerhut/clojure-benchmarks.git and more importantly, that means they can be good in optimizing useful code, too :-) I was pondering this question "If a pure

Re: Minor macro help

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 8:01 PM, CuppoJava wrote: > > You can use eval to retrieve the value of a-map when the macro is > expanded. > > (let [value (eval a-map)] > `(binding ~(vec (process-a-map value)) ~...@forms)) > > I've programmed some substantial programs now in Clojure though, and > I've ne

Re: What happened to clojure.contrib web site ?

2009-08-03 Thread James Sofra
I think he may mean this http://code.google.com/p/clojure-contrib/wiki/OverviewOfContrib Is it still being updated? It says "Updated Jun 15, 2009 by tomfaulhaber" Cheers, James On Aug 4, 10:24 am, Mike Hinchey wrote: > Do you mean this?http://clojure.org/libraries --~--~-~--~~---

Re: What happened to clojure.contrib web site ?

2009-08-03 Thread ataggart
Here's the well-hidden, auto-generated docs for clojure-contrib: http://richhickey.github.com/clojure-contrib/ On Aug 3, 5:41 pm, James Sofra wrote: > I think he may mean > thishttp://code.google.com/p/clojure-contrib/wiki/OverviewOfContrib > Is it still being updated? > It says "Updated Jun

Re: What happened to clojure.contrib web site ?

2009-08-03 Thread Vagif Verdi
On Aug 3, 6:19 pm, ataggart wrote: > Here's the well-hidden, auto-generated docs for clojure-contrib: > > http://richhickey.github.com/clojure-contrib/ > Thx. That's what i've been looking for. --~--~-~--~~~---~--~~ You received this message because you are sub

Re: Package manager proposal

2009-08-03 Thread Phil Hagelberg
James Reeves writes: > I've been sketching out a design for a package manager for Clojure, > similar to Rubygems. To the best of my knowledge, there's no real > equivalent to this in Java-land. > > I'm looking for suggestions, criticisms, or for someone to tell me > that Java already has a packa

Re: Minor macro help

2009-08-03 Thread Meikel Brandmeyer
Hi, On Aug 3, 11:43 pm, samppi wrote: >   (def my-map {:a 2}) >   (defn process-a-map [arg] ...) >     ; Turns maps into corresponding vectors. >     ; (process-a-map my-map) returns ['*foo* :blah]. > >   (my-macro a-map ; Last statement >     (do-something)) The answer which should leave the

Re: Memfn: what does it mean?

2009-08-03 Thread Meikel Brandmeyer
Hi, On Aug 3, 10:10 pm, John Harrop wrote: > (defn and-ns >   "A non-short-circuiting \"and\" usable in reduce etc." >   ([] true) >   ([a] a) >   ([a b] (and a b)) >   ([a b & more] (reduce and-ns (and a b) more))) Don't think to complicated. (reduce #(and %1 %2) coll) This should d