Hi all,
I finished porting my model to clojure, and am now trying to get it
to run concurrently. During the porting I already to care to wrap
the main functions (birth [loc], death [loc] etc) in dosyncs, and all
the slots in the world-vector are refs.
I've the feeling those are all fine, and I a
On Sun, Dec 14, 2008 at 5:48 AM, bOR_ wrote:
>
> Can anyone tell me what mistake I am making?
>
> (time
> (do
> (dotimes i popsize
>(send-off (agent i)
> (doseq a [birth death infect infect evolve
> evolve evolve evolve evolve] (a i
> (println "We've send
Jim,
> I would make some minor changes in two places. I would write with-
> monad as:
Obviously this is a better version.
> And I would write m-lift as
I like that one as well.
I have uploaded a new version that integrates your improvements.
Another one is that the monad operations are now
Thanks! Needed only a small change then :)
(time
(do
(dotimes i popsize
(doseq a [birth death infect infect evolve evolve evolve
evolve evolve]
(send-off (agent i) a)))
(dosync (commute year inc
(report)
--~--~-~--~~~---~--~--
On Sun, Dec 14, 2008 at 8:49 AM, bOR_ wrote:
>
> Thanks! Needed only a small change then :)
>
> (time
> (do
> (dotimes i popsize
>(doseq a [birth death infect infect evolve evolve evolve
> evolve evolve]
> (send-off (agent i) a)))
> (dosync (commute year inc
The order doesn't matter, and a somewhat mixed order would even be a
welcome side-effect of the whole concurrency bit.
What does worry me is that the agents are very short-lived. The
longest of these tasks takes 0.5msec (any evolution event), so I am
not sure if spawning all these agents is worth
On Saturday 13 December 2008 23:19, Mark H. wrote:
> So I'm going to stop pretending like I'm an expert and actually post
> some Clojure code. Be constructively critical 'cause I'm a n00b in
> that regard ;-) This is a pseudorandom number generator for the
> Gaussian (0,1) distribution.
>
> ...
I see that the file clojure/contrib/test_clojure.clj does a "use" on
clojure.contrib.test-is.
That source file doesn't "use" anything else.
Is the soure file clojure/contrib/test_is/test_is.clj used by anything
or is it obsolete code?
--
R. Mark Volkmann
Object Computing, Inc.
--~--~-~-
Hi, I'm just learning Clojure but I thought I would do a little
experiment to see where Clojure sits performance-wise compared to a
number of other languages on the old Fibonacci sequence. I think it
handles itself quite well.
The full writeup:
http://www.mikeperham.com/2008/12/13/clojure-vs-rub
On Dec 14, 9:01 am, Mike Perham wrote:
> Hi, I'm just learning Clojure but I thought I would do a little
> experiment to see where Clojure sits performance-wise compared to a
> number of other languages on the old Fibonacci sequence. I think it
> handles itself quite well.
>
> The full writeup
I've not had time to look at the source yet, but want to note that the
exception with Swank happens at r1158:
r1158 | rhickey | 2008-12-12 21:37:12 -0500 (Fri, 12 Dec 2008) | 2
lines
force instance member interpretation of (.method ClassName), e.g.
(.getMethods String) works
Any idea how this c
Ah, ok... I would have assumed that would be labeled as O(2n). Didn't
realize that was rolled into the constant factor. So, when graphed,
ANY linear function is O(n), no matter how "steep" the line is?
Obviously I have some reading to do.
Thanks for the clarification,
-Luke
On Dec 13, 6:35 pm,
yep. a function f(n) is O(n) if there are constants c and n0 such that f(n)
<= c * n for all n >= n0.
sometimes you do care about the c and the n0, though.
On Sun, Dec 14, 2008 at 12:41 PM, levand wrote:
>
> Ah, ok... I would have assumed that would be labeled as O(2n). Didn't
> realize that was
On Dec 14, 2:01 pm, Mike Perham wrote:
> Hi, I'm just learning Clojure but I thought I would do a little
> experiment to see where Clojure sits performance-wise compared to a
> number of other languages on the old Fibonacci sequence. I think it
> handles itself quite well.
Interesting, but beca
On Sun, Dec 14, 2008 at 11:06 AM, Michel Salim wrote:
>
>
>
> On Dec 14, 9:01 am, Mike Perham wrote:
>> Hi, I'm just learning Clojure but I thought I would do a little
>> experiment to see where Clojure sits performance-wise compared to a
>> number of other languages on the old Fibonacci sequenc
This follows from the recent micro-benchmarking discussion, though as
it concerns a potential bug, I'm starting a new thread.
With this (very inefficient) implementation of fib,
(defn fib [n]
(if (<= n 1)
1
(+ (fib (dec n)) (fib (- n 2)
computing (fib 40) takes, give or take, 12 s
On 14.12.2008, at 08:19, Mark H. wrote:
> So I'm going to stop pretending like I'm an expert and actually post
> some Clojure code. Be constructively critical 'cause I'm a n00b in
> that regard ;-) This is a pseudorandom number generator for the
> Gaussian (0,1) distribution.
...
Isn't that t
Nice code chouser, always nice to see a succinct functional example.
On Dec 13, 10:15 am, Chouser wrote:
> On Sat, Dec 13, 2008 at 10:41 AM, Dmitri wrote:
>
> > I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/
> > it reads stdin and counts the occurrences of words, however
On Dec 14, 12:08 pm, James Reeves wrote:
> On Dec 14, 2:01 pm, Mike Perham wrote:
>
> > Hi, I'm just learning Clojure but I thought I would do a little
> > experiment to see where Clojure sits performance-wise compared to a
> > number of other languages on the old Fibonacci sequence. I think
On Sunday 14 December 2008 09:00, harrison clarke wrote:
> yep. a function f(n) is O(n) if there are constants c and n0 such
> that f(n) <= c * n for all n >= n0.
>
> sometimes you do care about the c and the n0, though.
To be sure.
And there can be times that, for the problem size you know you
I've notice that the latest builds of Clojure now use strings for keys
in proxy mappings, whilst in the past they used to use symbols. Was
this change deliberate?
- James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Group
On Sunday 14 December 2008 10:40, James Reeves wrote:
> I've notice that the latest builds of Clojure now use strings for
> keys in proxy mappings, whilst in the past they used to use symbols.
> Was this change deliberate?
Yes. Rich pointed this out in the SVN commit commentary for 1159:
"proxy
Hi,
I ran into a special case that I'd like to avoid. When (filter ...) is
either applied to an empty collection or the filter predicate returns
false for all the elements in the supplied collection, filter returns
nil.
Would it be acceptable and desirable for it to return and empty list in
work> (.getName (.getClass 0))
"java.lang.Integer"
work> (.getName java.lang.Integer)
; Evaluation aborted.
Why does the second expression fail?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To po
On Sunday 14 December 2008 11:08, Randall R Schulz wrote:
> Hi,
>
> I ran into a special case that I'd like to avoid. When (filter ...)
> is either applied to an empty collection or the filter predicate
> returns false for all the elements in the supplied collection, filter
> returns nil.
>
> Woul
--- On Sun, 12/14/08, David wrote:
> work> (.getName java.lang.Integer)
> ; Evaluation aborted.
>
> Why does the second expression fail?
Would that work in Java?
Dave
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Group
On Dec 14, 2:08 pm, Randall R Schulz wrote:
> Hi,
>
> I ran into a special case that I'd like to avoid. When (filter ...) is
> either applied to an empty collection or the filter predicate returns
> false for all the elements in the supplied collection, filter returns
> nil.
>
> Would it be acc
More detail: I'm on a MBP with 2.2Ghz Core 2 Duo. I used Apple's
standard GCC 4.0.1 to compile with no settings (gcc fib.c -o fib).
The same code with Apple's GCC 4.2 produced the same time, I didn't
think to use an optimization flag as I haven't written C in a decade.
It looks like Michael's re
On Dec 14, 2:26 pm, David wrote:
> work> (.getName (.getClass 0))
> "java.lang.Integer"
>
> work> (.getName java.lang.Integer)
> ; Evaluation aborted.
>
> Why does the second expression fail?
There used to be a long answer as to why:
http://groups.google.com/group/clojure/msg/8fc6f0e9a5800e4b
When IS an appropriate time to use '()? It's in the language, so I
assume there must be at least one good use case.
Recently, I was writing a function that yields a sequence of all the
subsequences of a given sequence, e.g.,
(subseqs '(1 2 3)) ->
(nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3))
I ha
Sneaky, but I bet I'll get confused by the extra functionality at some point.
--- On Sun, 12/14/08, Rich Hickey wrote:
> There used to be a long answer as to why:
>
> http://groups.google.com/group/clojure/msg/8fc6f0e9a5800e4b
>
> Now there is a short one - it does work!
--~--~-~--~-
On Sunday 14 December 2008 11:08, Randall R Schulz wrote:
> ...
It turns out that flatten (from clojure.contrib.seq-utils) is really
where I go wrong with my simple version of gather-slot-values.
Does this makes sense (specifically the last one)?
user=> (flatten [])
nil
user=> (flatten ())
ni
My mistake; unchecked operations work just fine if their arguments
(including constants) are given type hints. What happens if unchecked-
add/sub/... is given an argument of unknown type, though? It still
seems to work, though slowly.
On Dec 14, 12:35 pm, Michel Salim wrote:
> This follows from
I've moved the codebase to the Eclipse Public License as of SVN 1160:
http://opensource.org/licenses/eclipse-1.0.php
EPL is the successor to CPL, and acceptable to Google Code and others.
It allows all the same usages as did CPL, is commercial friendly etc.
Contrib should move over ASAP.
Than
On Dec 14, 6:57 pm, Randall R Schulz wrote:
> Yes. Rich pointed this out in the SVN commit commentary for 1159:
Ah, somehow I managed to miss that message! I should really pay closer
attention.
- James
--~--~-~--~~~---~--~~
You received this message because you a
So I have some code that looks somewhat like:
(update-in node [:index :x] set/union #{:y})
This seems fine as long as there's already a set in the desired spot.
However, since update-in will kindly build the map structure for you
if it doesn't already exist, I figured it would be nice not to hav
I'm trying AOT compilation for the first time. Here's what I did.
- created the directory com/ociweb below my current directory
- created the source file math.clj with the following content
(ns com.ociweb.math)
(defn fib [n] (reduce * (range 2 (inc n
- started a REPL in the current director
How to dispatch on specific argument(s) of a function?
example:
(defmulti group )
(defmethod group ??? [xs n]
(loop [acc nil
x xs]
(if (not x)
(reverse acc)
(recur (cons (take n x) acc) (drop n x)
Here I want to dispatch on the class of the first argument xs
Hello.
I am having problems with "gen-and-load-class". I have a file with an
example from the wiki book:
(gen-and-load-class 'user.UserException :extends Exception)
(defn user-exception-test []
(try
(throw (new user.UserException "msg: user exception was here!!"))
(catch user.UserExce
Mark Volkmann wrote:
> I'm trying AOT compilation for the first time. Here's what I did.
>
> - created the directory com/ociweb below my current directory
> - created the source file math.clj with the following content
>
> (ns com.ociweb.math)
> (defn fib [n] (reduce * (range 2 (inc n
>
> - st
I've updated the Clojure classes graph (thanks for the push, R.
Schulz!) The new version includes the newest classes as well as Java
interfaces that are applicable. These latter are shown inside
diamonds.
A couple different .svg and .png versions are available here, along
with the code used to
I had some trouble understanding this at first too.
"Here I want to dispatch on the class of the first argument xs. "
on the first aargument, ie xs, or on the first argument of xs?
This should work:
(defmulti group
(fn [xs n]
(class xs)))
(defmulti group
(fn [xs n]
(class (first xs
Hi,
Looks like patch is already applied, but i now i get following error
after "M-."
java.lang.IllegalArgumentException: No matching field found: separator
for class java.lang.Class (NO_SOURCE_FILE:0)
[Thrown class clojure.lang.Compiler$CompilerException]
I updated everything clojure related
Ok.. seems like the short lifespan of the agent-threads makes it hard
for the program
to actually start using its (in this case 2) multiple cpu's.
The next program has no problem filling both cpu's together for 199%
(top, linux), whilst the simulation
has trouble getting above 110%, but occasiona
Konrad,
I did some more work from the paper the parser combinator is based
on. From that I built what I think is a state monad transformer:
(defn stateT [m]
(monad [m-result (fn [v]
(fn [s]
((:m-result m) (list v s
m-bind (fn [st
Also, I came across set-state and fetch-state being implemented in
terms of update-state.
(defn set-state [s]
(update-state (fn [x] s)))
(defn fetch-state []
(update-state identity))
Jim
--~--~-~--~~~---~--~~
You received this message because
This is due to the change in clojure svn 1158. (.method ClassName ...)
syntax has been changed to call java.lang.Class method for ClassName,
not static field/method any more. Use namespace syntax instead.
diff --git a/swank/commands/basic.clj b/swank/commands/basic.clj
index ac0736f..4705cd5 1006
On Sun, Dec 14, 2008 at 3:45 PM, Albert Cardona wrote:
>
> Mark Volkmann wrote:
>> I'm trying AOT compilation for the first time. Here's what I did.
>>
>> - created the directory com/ociweb below my current directory
>> - created the source file math.clj with the following content
>>
>> (ns com.o
On Dec 14, 6:09 am, Randall R Schulz wrote:
> On Saturday 13 December 2008 23:19, Mark H. wrote:
>
> > So I'm going to stop pretending like I'm an expert and actually post
> > some Clojure code. Be constructively critical 'cause I'm a n00b in
> > that regard ;-) This is a pseudorandom number ge
Hi,
I have quite a bit of Java code with I/O capabilities that generally
support both PrintStream and PrintWriter. I was a bit perplexed when I
tried to apply one of these methods to *out* and was rebuffed thusly:
java.lang.IllegalArgumentException:
No matching method found: printMessage for
On Dec 14, 9:40 am, Konrad Hinsen wrote:
> Isn't that the standard Box-Muller transform?
Ah, yes, now I know what to call it ;-) Yes, it's a particular
implementation of the Box-Muller transform that is designed to avoid
trig functions.
http://en.wikipedia.org/wiki/Marsaglia_polar_method
> (d
On Sun, Dec 14, 2008 at 9:18 AM, Mark Volkmann
wrote:
>
> I see that the file clojure/contrib/test_clojure.clj does a "use" on
> clojure.contrib.test-is.
> That source file doesn't "use" anything else.
> Is the soure file clojure/contrib/test_is/test_is.clj used by anything
> or is it obsolete co
On Dec 14, 3:16 pm, Randall R Schulz wrote:
> Does this makes sense (specifically the last one)?
>
> user=> (flatten [])
> nil
>
> user=> (flatten ())
> nil
>
Yes; the empty sequence is just nil.
> user=> (flatten nil)
> (nil)
>
That does look like a bug.
--
Michel
--~--~-~--~~--
Hi,
The doc text for symbol is:
user=> (doc symbol)
-
clojure.core/symbol
([name] [ns name])
Returns a Symbol with the given namespace and name.
However, the "ns" argument must be a String, not a namespace.
Would it be reasonable to allow an actual namespace as the n
On 14.12.2008, at 18:40, Konrad Hinsen wrote:
> (defn rng-uniform
>"Return an infinite lazy sequence of random numbers"
>[]
>(drop 1 (iterate (fn [_] (rand)) nil)))
>
> (defn transform-to-gaussian
>"Transform a sequence of uniform random number in the interval
> [0, 1)
> int
I am porting some examples from Paul Graham's "On Lisp" book.
I have a problem with this one (fig 5. 4 page 67):
(defun fif (if then &optional else)
#'(lambda (x)
(if (funcall if x)
(funcall then x)
(if else (funcall else x)
My implementation:
(defn fif [iff then
#(fif even? (fn [x] (* 2 x))) has no % sign in it, so it is a
function of zero arguments, which is not something that map can use.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this gro
On Sat, Dec 13, 2008 at 10:59 PM, Wayne R wrote:
>
> I've got an issue where the clojure.xml/parse and /emit functions are
> not symmetric with respect to how attributes are read and written.
> The parser decodes HTML entities (e.g. & -> &) however the emitter
> does not re-encode them:
Good cat
> (map #(fif even? (fn [x] (* 2 x))) [3 4])
Your fif returns a function. So probably what you wanted to do was:
user=> (map (fif even? (fn [x] (* 2 x))) [3 4])
(nil 8)
fif is returning an unnamed function which accepts one argument and
can thus be mapped to [3 4]
#(...) creates an unnamed functi
Just thought of a better comparison:
(map (fif even? #(* 2 %1)) [3 4])
is indeed shorter than:
(map #(if (even? %1) (* 2 %1)) [3 4])
Regards,
Tim.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To
> user=> (flatten nil)
> (nil)
Not a bug.
flatten returns a sequence - in this case a sequence containing 'nil.
How else would you flatten on nil?
In the former cases the flatten returns the seq - nil
Can Clojure return an empty sequence otherwise?
(def x ())
(first x)
=> nil
(def y x)
y
=> n
> user=> (flatten nil)
> (nil)
Not a bug.
flatten returns a sequence - in this case a sequence containing 'nil.
How else would you flatten on nil?
In the former cases the flatten returns the seq - nil
Can Clojure return an empty sequence otherwise?
(def x ())
(first x)
=> nil
(def y x)
y
=> n
On Sat, Dec 13, 2008 at 5:51 AM, Rich Hickey wrote:
> No you can't, for the same reasons you can't for Iterator or
> Enumeration seqs. Again it comes down to abstractions, and the
> abstraction for (seq x) is one on persistent collections. It presumes
> that (seq x) is referentially transparent,
63 matches
Mail list logo