Re: (con)current confusion

2008-12-14 Thread Chouser
On Sun, Dec 14, 2008 at 5:48 AM, bOR_ boris.sch...@gmail.com 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

Re: The return of the monads: lessons learned about macros

2008-12-14 Thread Konrad Hinsen
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

Re: (con)current confusion

2008-12-14 Thread bOR_
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)

Re: (con)current confusion

2008-12-14 Thread Chouser
On Sun, Dec 14, 2008 at 8:49 AM, bOR_ boris.sch...@gmail.com 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

Re: (con)current confusion

2008-12-14 Thread bOR_
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

Re: DISCUSS: replace (rand)

2008-12-14 Thread Randall R Schulz
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. ... [

Fibonacci: Clojure vs the World

2008-12-14 Thread Mike Perham
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:

Re: Fibonacci: Clojure vs the World

2008-12-14 Thread Michel Salim
On Dec 14, 9:01 am, Mike Perham mper...@gmail.com 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

Re: Bug in read-line?

2008-12-14 Thread Michel Salim
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

Re: Functional programming newbie question

2008-12-14 Thread levand
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,

Re: Functional programming newbie question

2008-12-14 Thread harrison clarke
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 luke.vanderh...@gmail.com wrote: Ah, ok... I would have assumed that would be labeled as O(2n).

Re: Fibonacci: Clojure vs the World

2008-12-14 Thread James Reeves
On Dec 14, 2:01 pm, Mike Perham mper...@gmail.com 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.

Re: performance question

2008-12-14 Thread Justin Henzie
Nice code chouser, always nice to see a succinct functional example. On Dec 13, 10:15 am, Chouser chou...@gmail.com wrote: On Sat, Dec 13, 2008 at 10:41 AM, Dmitri dmitri.sotni...@gmail.com wrote: I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/ it reads stdin and

Re: Fibonacci: Clojure vs the World

2008-12-14 Thread Michel Salim
On Dec 14, 12:08 pm, James Reeves weavejes...@googlemail.com wrote: On Dec 14, 2:01 pm, Mike Perham mper...@gmail.com 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

Re: Functional programming newbie question

2008-12-14 Thread Randall R Schulz
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 need

Proxy mappings now use strings for keys - deliberate?

2008-12-14 Thread James Reeves
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

Re: Proxy mappings now use strings for keys - deliberate?

2008-12-14 Thread Randall R Schulz
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

Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Randall R Schulz
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

Java interop question

2008-12-14 Thread David
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 post to

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Randall R Schulz
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. Would it be

Re: Java interop question

2008-12-14 Thread Dave Newton
--- 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 Groups

Re: Fibonacci: Clojure vs the World

2008-12-14 Thread Mike Perham
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: Java interop question

2008-12-14 Thread Rich Hickey
On Dec 14, 2:26 pm, David dsieg...@yahoo.com 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:

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Mark Engelberg
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

Re: Java interop question

2008-12-14 Thread Dave Newton
Sneaky, but I bet I'll get confused by the extra functionality at some point. --- On Sun, 12/14/08, Rich Hickey richhic...@gmail.com 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!

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Randall R Schulz
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 ()) nil

Re: Bug in unchecked operations?

2008-12-14 Thread Michel Salim
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 michel.syl...@gmail.com

Move to Eclipse Public License

2008-12-14 Thread Rich Hickey
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.

Re: Proxy mappings now use strings for keys - deliberate?

2008-12-14 Thread James Reeves
On Dec 14, 6:57 pm, Randall R Schulz rsch...@sonic.net 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

Set union weirdness

2008-12-14 Thread kwatford
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

learning about AOT

2008-12-14 Thread Mark Volkmann
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

Multimethod dispatch on one or more specific arguments

2008-12-14 Thread Oscar Picasso
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

Problems with gen-and-load-class (defn user-exception-test [] (try (throw (new user.UserException msg: user exception was here!!)) (catch user.UserException e (prn caught excep

2008-12-14 Thread Tommy
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

Re: learning about AOT

2008-12-14 Thread Albert Cardona
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 - started a

Clojure classes graph (was chart.png)

2008-12-14 Thread Chouser
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

Re: Multimethod dispatch on one or more specific arguments

2008-12-14 Thread ssecorp
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

Re: Patch: precompiling Clojure core sources in Ant build script

2008-12-14 Thread kunnar
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

Re: (con)current confusion

2008-12-14 Thread bOR_
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

Re: The return of the monads: lessons learned about macros

2008-12-14 Thread jim
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

Re: The return of the monads: lessons learned about macros

2008-12-14 Thread jim
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

Re: Patch: precompiling Clojure core sources in Ant build script

2008-12-14 Thread Feng
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

Re: learning about AOT

2008-12-14 Thread Mark Volkmann
On Sun, Dec 14, 2008 at 3:45 PM, Albert Cardona sapri...@gmail.com 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

Re: DISCUSS: replace (rand)

2008-12-14 Thread Mark H.
On Dec 14, 6:09 am, Randall R Schulz rsch...@sonic.net 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

Best Choice of Java Class For *out*

2008-12-14 Thread Randall R Schulz
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

Re: DISCUSS: replace (rand)

2008-12-14 Thread Mark H.
On Dec 14, 9:40 am, Konrad Hinsen konrad.hin...@laposte.net 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.

Re: test-is source

2008-12-14 Thread Chouser
On Sun, Dec 14, 2008 at 9:18 AM, Mark Volkmann r.mark.volkm...@gmail.com 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

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Michel Salim
On Dec 14, 3:16 pm, Randall R Schulz rsch...@sonic.net 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

Acceptable Arguments to Two-Argument (symbol ...)

2008-12-14 Thread Randall R Schulz
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 ns

Re: DISCUSS: replace (rand)

2008-12-14 Thread Konrad Hinsen
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) into a

On Lisp - porting problem

2008-12-14 Thread Oscar Picasso
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

Re: On Lisp - porting problem

2008-12-14 Thread Mark Engelberg
#(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

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Mon Key
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 = nil

Re: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?

2008-12-14 Thread Mon Key
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 = nil

Re: Running out of memory when using filter?

2008-12-14 Thread Mark Engelberg
On Sat, Dec 13, 2008 at 5:51 AM, Rich Hickey richhic...@gmail.com 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