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-
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
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
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
> 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
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
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
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
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
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
> 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
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
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:
=> (
> 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
> (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
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=
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
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
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
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
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
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
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
23 matches
Mail list logo