Re: Q: is there a better way to do this

2009-09-21 Thread Timothy Pratley
I can't claim this is better, but it is shorter - I simply removed what seemed like some unnecessary syntax: (def data (ref ())) (def consuming (ref false)) (defn producer [] (if (dosync (if (not @consuming) (alter data conj 1))) (recur))) (defn consumer [] (dosync (ref-

Q: is there a better way to do this

2009-09-21 Thread Roger Gilliar
This is some sort of repost from yesterday. But I hope that this one describes my problem more precisely. I have n threads that produce something. At some point in time a consumer starts and if the consumer starts, no more data should be produced. Right now I can only come up with the foll

Re: How to override .toString for a struct?

2009-09-21 Thread Mike Hinchey
You can (defmethod print-method), but you'll need a :type in the meta of your struct. -Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.co

How to override .toString for a struct?

2009-09-21 Thread Jung Ko
Hi, Can someone teach me how I can override the "toString" method for a struct ? Here's a code snippet that shows what I'm trying to do: user> (defstruct bookinfo :book :filename) user> (struct bookinfo "hello" "world") => {:book "hello", :filename "world"} I would like to override the "toStri

Re: exception: agents + swing

2009-09-21 Thread Raoul Duke
> The info is there, but as you say it isn't very obvious. > I'm happy to submit a trivial patch which would change the error > message to include the agent's error string. holy toledo, thanks! --~--~-~--~~~---~--~~ You received this message because you are subscr

Re: exception: agents + swing

2009-09-21 Thread Timothy Pratley
The info is there, but as you say it isn't very obvious. I'm happy to submit a trivial patch which would change the error message to include the agent's error string. For example, before patch: user=> (def a (agent 0)) user=> (send a (partial / 10)) user=> @a java.lang.Exception: Agent has errors

Re: Applying Java methods.

2009-09-21 Thread pmf
On Sep 21, 11:22 pm, sross wrote: >  I'm looking for a bit of advice for calling a java method which has a > few different signatures (such as Connection.prepareStatement). >  Is there a cleaner way of passing a variable number of arguments to > the method, such as > > (apply (memfn prepareStatem

Applying Java methods.

2009-09-21 Thread sross
Hi All, I'm looking for a bit of advice for calling a java method which has a few different signatures (such as Connection.prepareStatement). Is there a cleaner way of passing a variable number of arguments to the method, such as (apply (memfn prepareStatement) (sql/connection) args) or is d

Re: Q: why doesn't this script terminate

2009-09-21 Thread John Harrop
On Mon, Sep 21, 2009 at 2:22 PM, Richard Newman wrote: > > > But this script doesn't terminate. I have to press ctr-c to end this > > script. It seems that there a still some threads active. why ? > > http://www.mail-archive.com/clojure@googlegroups.com/msg13865.html Your response was longer th

Metadata and sequences

2009-09-21 Thread samppi
Why does metadata not work on conj-ed sequences? Clojure 1.0.0- user=> (def a (with-meta [1 2 3] {:a 2})) #'user/a user=> ^(conj a 4) {:a 2} user=> (def b (with-meta (seq [1 2 3]) {:a 2})) #'user/b user=> ^b {:a 2} user=> ^(conj b 4) nil --~--~-~--~~~---~--~~ You

Re: Q: why doesn't this script terminate

2009-09-21 Thread Richard Newman
> But this script doesn't terminate. I have to press ctr-c to end this > script. It seems that there a still some threads active. why ? http://www.mail-archive.com/clojure@googlegroups.com/msg13865.html --~--~-~--~~~---~--~~ You received this message because you a

Q: why doesn't this script terminate

2009-09-21 Thread Roger Gilliar
I call test.clj like this: java -cp /Users/roger/Library/clojure/clojure-1.0.0.jar clojure.main test.clj The script is: (defn syncnow [] (println "Hello World") ) (dorun (pcalls syncnow syncnow syncnow)) But this script doesn't terminate. I have to press ctr-c to

Re: delays are forced by deref too early?

2009-09-21 Thread Christophe Grand
On Mon, Sep 21, 2009 at 6:48 PM, patrickdlogan wrote: > > > (force del) ; note that @del would be equivalent here > > This is at the core of my question. I did not understand that a delay > is something that can be deref'd until I read the source. > Well, it's documented but not on #'delay: => (

Re: exception: agents + swing

2009-09-21 Thread Raoul Duke
> The error would have occured in the (send ) where the drawing is > done. @agent is not causing it, but you do get an exception there > because of the previous exception while drawing. To debug this I > suggest inserting some printlns into the function you are sending. thanks! that makes sen

Re: delays are forced by deref too early?

2009-09-21 Thread patrickdlogan
> (force del) ; note that @del would be equivalent here This is at the core of my question. I did not understand that a delay is something that can be deref'd until I read the source. Knowing now that a delay does behave this way, I can work with it as such. Given the doc string for delay, I was

Re: delays are forced by deref too early?

2009-09-21 Thread Christophe Grand
Hi Patrick, If that really annoys you, you can tell the repl to display Delay instances as dumb objects: (defmethod print-method clojure.lang.Delay [x w] ((get-method print-method Object) x w)) user=> (defmethod print-method clojure.lang.Delay [x w] ((get-method print-method Object) x w)) # user=

Re: delays are forced by deref too early?

2009-09-21 Thread Jarkko Oranen
On Sep 21, 6:53 pm, patrickdlogan wrote: > I expected a delay only to be forced by an explicit call to force. > instead it looks like, being a kind of IDeref, a delay will be forced > by the REPL. > > e.g. > > user=> (def del (delay (println "printed") (+ 2 3))) > #'user/del > user=> del > printe

delays are forced by deref too early?

2009-09-21 Thread patrickdlogan
I expected a delay only to be forced by an explicit call to force. instead it looks like, being a kind of IDeref, a delay will be forced by the REPL. e.g. user=> (def del (delay (println "printed") (+ 2 3))) #'user/del user=> del printed # user=> (force del) 5 The documentation seems to imply t

Re: Q: dosync semantics

2009-09-21 Thread Roger Gilliar
Hi ! Am 21.09.2009 um 15:55 schrieb Jarkko Oranen: > > In any case, the synchronisation guarantees that if you have a > starting list A, either the remove or the append operation will be > applied to it, producing A', and the remaining operation will be > applied to A', producing the final value o

Re: Q: dosync semantics

2009-09-21 Thread Jarkko Oranen
On Sep 21, 4:38 pm, Roger Gilliar wrote: > I still have some problems to correctly understand the dosync   > semantic.  What happens exaclty if two threads try to modify the same   > list: Nitpick: you're not modifying any lists. :) The only mutating things are the Refs > > Example > > thread

Q: dosync semantics

2009-09-21 Thread Roger Gilliar
I still have some problems to correctly understand the dosync semantic. What happens exaclty if two threads try to modify the same list: Example thread 1: (dosync append an item to a list ... ) thread 2: (dosync remove an item from a list .. ) Is it true that If thread 1 is

Re: OutOfMemoryError with loop/recur

2009-09-21 Thread Tassilo Horn
John Harrop writes: Hi John, >> Although that doesn't really help, the normal `reduce' doesn't do >> better. >> >> (reduce + (take 100 (iterate inc 1))) ; works >> (reduce + (take 1000 (iterate inc 1))) ; OutOfMemoryError > > Are you sure? I'd expect that with > > (def integers (iterat

Re: exception: agents + swing

2009-09-21 Thread Timothy Pratley
The error would have occured in the (send ) where the drawing is done. @agent is not causing it, but you do get an exception there because of the previous exception while drawing. To debug this I suggest inserting some printlns into the function you are sending. On Sep 21, 2:24 pm, Raoul Duk