Re: Count the number of times a function was applied

2010-01-31 Thread Gabi
update-in for every function call might slow things down considerably.
Maybe using an atom referencing to native Java array for counts is
better (in which swap! would just use aset to new count)

On Jan 31, 5:45 pm, "Stephen C. Gilardi"  wrote:
> On Jan 31, 2010, at 8:35 AM, Gabi wrote:
>
> > Is there any efficient way to get the number of times a given
> > function was executed (in run time not during profiling)? Maybe with
> > some clever use of its metadata ?
>
> Clojure function calls are low-level operations for efficiency. I'm not aware 
> of any easy hook for implementing that kind of profiling in Clojure. If 
> you're interested in a particular function, consider dedicating an atom to 
> holding a count of its calls and incrementing the value held by that atom on 
> each call:
>
>         user=> (def sqr-call-count (atom 0))
>         #'user/sqr-call-count
>         user=> (defn sqr [x] (swap! sqr-call-count inc) (* x x))
>         #'user/sqr
>         user=> (sqr 3)
>         9
>         user=> @sqr-call-count
>         1
>         user=> (def b (map sqr (range 100)))
>         #'user/b
>         user=> @sqr-call-count ; map is lazy
>         1
>         user=> b
>         (0 1 4 9 16 25 36 ... 9801)
>         user=> @sqr-call-count
>         101
>         user=>
>
> It's possible such a count could be kept in the function's metadata as you 
> suggest. If this kind of count were needed for a large number of functions, I 
> would stick with a single atom that held a map from function to count (or var 
> to count) that I updated with swap!, update-in, and inc.
>
> --Steve

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Count the number of times a function was applied

2010-01-31 Thread Gabi
 Is there any efficient way to get the number of times a given
function was executed (in run time not during profiling)? Maybe with
some clever use of its metadata ?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


def vs intern

2010-01-31 Thread Gabi
I wonder what is the difference between the two. Is there a
difference?
I want do define/intern functions at runtime. Which should I use ?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Suggestion: Get rid of "java.lang.Exception: EOF while reading.."

2010-01-27 Thread Gabi
Superb.  Getting a fix so fast.. Open Source at its best!
I tried it. Works as expected.

On Jan 27, 8:50 pm, Chouser  wrote:
> On Wed, Jan 27, 2010 at 1:00 PM, Rich Hickey  wrote:
>
> > On Jan 27, 11:22 am, Chouser  wrote:
> >> On Wed, Jan 27, 2010 at 4:03 AM, Gabi  wrote:
> >> > This exception is the biggest time waster for me when working with
> >> > Clojure. It doesn't give you a hint of where the problem really is.
> >> > I strongly suggest to improve parse error messages to contain
> >> > meaningful info.
>
> >> I just wrote a patch to LispReader that in many cases can produce
> >> an exception like:
>
> >>   java.lang.Exception: EOF while reading, starting at line 7 (bad.clj:15)
>
> >> So while bad.clj:15 indicates the file name and the fact that
> >> line 15 is the last one of the file, "starting at line 7" points
> >> out the line where the unclosed grouping construct started.  This
> >> might be useful.
>
> >> Rich, care for a bug and patch for this?
>
> > Sure - thanks!
>
> Done:http://www.assembla.com/spaces/clojure/tickets/249
>
> --Chouserhttp://joyofclojure.com/

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Suggestion: Get rid of "java.lang.Exception: EOF while reading.."

2010-01-27 Thread Gabi
Yes Rich, Please approve this patch!

On Jan 27, 6:22 pm, Chouser  wrote:
> On Wed, Jan 27, 2010 at 4:03 AM, Gabi  wrote:
> > This exception is the biggest time waster for me when working with
> > Clojure. It doesn't give you a hint of where the problem really is.
> > I strongly suggest to improve parse error messages to contain
> > meaningful info.
>
> I just wrote a patch to LispReader that in many cases can produce
> an exception like:
>
>   java.lang.Exception: EOF while reading, starting at line 7 (bad.clj:15)
>
> So while bad.clj:15 indicates the file name and the fact that
> line 15 is the last one of the file, "starting at line 7" points
> out the line where the unclosed grouping construct started.  This
> might be useful.
>
> Rich, care for a bug and patch for this?
>
> --Chouserhttp://joyofclojure.com/

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Suggestion: Get rid of "java.lang.Exception: EOF while reading.."

2010-01-27 Thread Gabi
This exception is the biggest time waster for me when working with
Clojure. It doesn't give you a hint of where the problem really is.
I strongly suggest to improve parse error messages to contain
meaningful info.

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Cyclic require

2010-01-24 Thread Gabi
As a side note, I didn't see anywhere in clojure docs that cyclic
references are forbidden.
And if it is forbidden, the Exception raised by the runtime should
reflect this instead of the odd "No
such var->.." exception

On Jan 24, 10:44 pm, Laurent PETIT  wrote:
> Some software principle are certainly above the languages used to
> solve a problem, even probably above programming paradigms (OOP,
> purely functional, etc.).
>
> Java certainly has good parts, and having promoted the role and
> importance of interfaces must certainly be accounted to its credit.
>
> But concerning the problem at hand, I think one could make an easy
> parallelism between callback classes in java and higher order
> functions in functional programming. It's just that's it's sooo easier
> and feels so much natural to do it in clojure ! :-)
>
> I agree with Stuart Halloway's answer, nothing more to add.
>
> I would just like to add that the term "module" has been used at one
> point where at first the debate was on namespaces.
> I'm not quite sure the notion of module I have in mind is really
> possible via the use of namespaces. For example (at least in the way
> I've learned and currently understand the concept of a module) it
> should be possible to load at the same time several "instances" of a
> module in an application, possibly even different versions of the same
> module. (of course to be used by different parts of the application).
> Not so much with namespaces. And I think that it's not their goal as
> well.
>
> But I can understand what the OP wanted to do. Those sort of things
> can be done with java packages, and the java compiler can also very
> easily allow one to make classes depend on each other in a circular
> manner.
> And since clojure and lisp in general is all about allowing the user
> to shoot himself in the foot by bringing the maximum power to him, I
> can understand the complaint. Same can be said concerning
> interdependent functions.
>
> Cheers,
>
> --
> Laurent
>
> 2010/1/24 Heinz N. Gies :
>
> > On Jan 24, 2010, at 17:12 , Stuart Halloway wrote:
>
> >> If the collaboration is deeply entwined, the two modules should be one 
> >> module. If one module uses another, but with occasional callbacks in the 
> >> other direction, use an interface or a protocol to define the backchannel.
>
> > That sounds horribly Javaish :(, I solved a problem like this by moving out 
> > the parts that A and B needed to C, but  it kind of is sad that since it 
> > feeled so much like Java here especially when it comes to interfaces and 
> > things like that ...
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: newbie question about ns and :require

2010-01-24 Thread Gabi
Sorry, I meant (cp/classpath) ..

On Jan 24, 6:06 pm, Gabi  wrote:
> Maybe try
> (ns my (:require [clojure.contrib.classpath :as cp]))
> (cp.classpath)
>
> On Jan 24, 5:28 pm, Manfred Lotz  wrote:
>
> > Hi all,
> > I'm stumbling about the very basics.
>
> > Calling clojure like this:
>
> > rlwrap java
> > -cp 
> > /home/manfred/clojure/clojure.jar:/home/manfred/clojure/clojure-contrib.jar
> > clojure.main
>
> > I try:
>
> > user=> (ns my (:require clojure.contrib.classpath))
> > nil
> > my=>
>
> > which to me looks fine.
>
> > But why does this fail?
>
> > my=> (classpath)
> > java.lang.Exception: Unable to resolve symbol: classpath in this
> > context (NO_SOURCE_FILE:2)
>
> > --
> > Hope it is not too much stupidity on my side,
> > Manfred

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: newbie question about ns and :require

2010-01-24 Thread Gabi
Maybe try
(ns my (:require [clojure.contrib.classpath :as cp]))
(cp.classpath)

On Jan 24, 5:28 pm, Manfred Lotz  wrote:
> Hi all,
> I'm stumbling about the very basics.
>
> Calling clojure like this:
>
> rlwrap java
> -cp 
> /home/manfred/clojure/clojure.jar:/home/manfred/clojure/clojure-contrib.jar
> clojure.main
>
> I try:
>
> user=> (ns my (:require clojure.contrib.classpath))
> nil
> my=>
>
> which to me looks fine.
>
> But why does this fail?
>
> my=> (classpath)
> java.lang.Exception: Unable to resolve symbol: classpath in this
> context (NO_SOURCE_FILE:2)
>
> --
> Hope it is not too much stupidity on my side,
> Manfred

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Cyclic require

2010-01-24 Thread Gabi
You know what? I am not sure that it smells so bad actually. What if I
have 2 modules that collaborate with each other and use each other
functions ? Why is this so bad?



On Jan 24, 5:32 pm, Laurent PETIT  wrote:
> Short answer: you can't. And yes, it's a "smell" (a bad one) if you
> want to achieve this.
>
> You have to somehow break the cycle :
>
>  * maybe acknowledge that ns a & b are strongly coupled since there's
> the need for a cyclic dependency, and merge them.
>    * sometimes one wants to have a & b to have things in different
> files. You can just (load) one from the other to include its content
> into the same namespace, but still have the namespace separated into
> several files.
>  * maybe move the common parts of a and be into a third namespace c
>  * ...
>
> Maybe if you give more info concerning your particular case, ...
>
> HTH,
>
> --
> Laurent
>
> 2010/1/24 Gabi :
>
> > This thing is driving me nuts. If I do a cyclic require(ns-a requires
> > ns-b and ns-b requires ns-a) I get exceptions complaining about "No
> > such var->.."
>
> > How can cyclic dependencies be done correctly in Clojure ? I know it
> > might be bad practice. But I really need it.
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Cyclic require

2010-01-24 Thread Gabi
This thing is driving me nuts. If I do a cyclic require(ns-a requires
ns-b and ns-b requires ns-a) I get exceptions complaining about "No
such var->.."

How can cyclic dependencies be done correctly in Clojure ? I know it
might be bad practice. But I really need it.

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Debugging in Clojure

2010-01-24 Thread Gabi
Be careful of deftrace. It has a bug that crashes when the defn'ed
funcs have string comment on the top of the func

On Jan 23, 7:02 am, ataggart  wrote:
> On Jan 22, 6:27 pm, Mike Meyer 
>
>
> 620...@mired.org> wrote:
> > On Fri, 22 Jan 2010 17:25:39 -0800
>
> > ajay gopalakrishnan  wrote:
> > > I dont mind using println. The problem is that needs to be inside a do or
> > > when ... and that is not really part of my code. When the time comes to
> > > remove the prints, i need to remove all these do blocks too. I can leave
> > > them as it is I guess, but then it is not neat and non-idiomatic. From all
> > > the replies, it seems that Debugging is going to be a pain in the Lisp 
> > > style
> > > languages. How do people in Lisp/Scheme debug it?
>
> > In the REPL. That's a pretty complete debugger, all by itself. In
> > something like SLIME, you get the ability to examine the call stack,
> > etc. while things are running.
>
> > The trace package just dumps arguments/results of functions while they
> > run. It's a primitive tool, but better than println's in many cases:
>
> > user it, then use dotrace:
>
> > user> (use 'clojure.contrib.trace)
> > nil
> > user> (defn foo [coll] (reduce + coll))
> > #'user/foo
> > user> (defn bar [coll] (map inc coll))
> > #'user/bar
> > user> (dotrace [foo bar] (foo (bar [1 1 1])))
> > TRACE t7043: (bar [1 1 1])
> > TRACE t7043: => (2 2 2)
> > TRACE t7044: (foo (2 2 2))
> > TRACE t7044: => 6
> > 6
> > user> (dotrace [foo +] (foo (bar [1 1 1])))
> > TRACE t7071: (foo (2 2 2))
> > TRACE t7072: |    (+ 2 2)
> > TRACE t7072: |    => 4
> > TRACE t7073: |    (+ 4 2)
> > TRACE t7073: |    => 6
> > TRACE t7071: => 6
> > 6
>
> > and so on.
>
> >      > --
> > Mike Meyer           http://www.mired.org/consulting.html
> > Independent Network/Unix/Perforce consultant, email for more information.
>
> > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org
>
> See, I *knew* there had to be a way to do it!  Clearly I wasn't
> grokking the docs for dotrace.  If the authors of of c.c.trace are
> amenable, I'm inclined to add this functionality to a variant of the
> c.c.logging/spy macro, something like:
>
> (spy [foo bar] (foo (bar [1 1 1])))

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: update-in! (?)

2010-01-21 Thread Gabi
I don't think zipper would help in this case

On Jan 21, 12:40 am, brianh  wrote:
> Any chance you could rethink your approach & use a zipper?
>
> On Jan 20, 9:32 am, Gabi  wrote:
>
> > I posted a question on SO about it. Interesting 
> > discussion:http://stackoverflow.com/questions/2102606/algorithm-to-implement-non...
>
> > On Jan 20, 5:39 pm, Christophe Grand  wrote:
>
> > > I concur: a map (or a sorted map if you need to emulate access to a
> > > subtree) can be an option.
>
> > > [[1 2] [3 4]] is represented by {[0 0] 1, [0 1] 2, [1 0] 3, [1 1] 4}
>
> > > On Wed, Jan 20, 2010 at 4:24 PM, Sean Devlin  
> > > wrote:
> > > > How about a sorted set w/ a custom comparator?  Of course, this rules
> > > > out transients, but maybe the flatness will make up for it?
>
> > > > On Jan 20, 10:15 am, Gabi  wrote:
> > > >> I need to add/delete much more frequently than just updating
> > > >> actually.
>
> > > >> On Jan 20, 4:59 pm, Sean Devlin  wrote:
>
> > > >> > Gabi,
> > > >> > A similar technique is used with sparse matrices.  You usually have
> > > >> > severals arrays, one for the non-zero elements, and another one for
> > > >> > indexing the column and a third for indexing the rows.
>
> > > >> >http://pasadena.wr.usgs.gov/office/baagaard/research/papers/thesis/fi...
>
> > > >> > This should be fast as long as you're only updating.  If you're
> > > >> > inserting/deleting, you might be able to get away with using a
> > > >> > collection of 1D trees.
>
> > > >> > Sean
>
> > > >> > On Jan 20, 9:18 am, Gabi  wrote:
>
> > > >> > > These vectors represent trees which need to updated very 
> > > >> > > frequently.
> > > >> > > So If there was an efficient way to use transients to represent
> > > >> > > transient trees the whole process would be much more efficient (so
> > > >> > > each update to a tree would be done in place instead of creating 
> > > >> > > new
> > > >> > > one.) As discussed above, naive usage of transients won't help.
> > > >> > > Another approach would be implement in Java, but I wish there would
> > > >> > > some way to achieve this directly from Clojure.
> > > >> > > Now that I think about it, maybe the solution is to represent the 
> > > >> > > tree
> > > >> > > as one dimensional vector instead of nested one (any good clojure
> > > >> > > algorithm for this ? Representing and traversing non binary trees 
> > > >> > > as
> > > >> > > one dimensional vector?)
>
> > > >> > > Jan 20, 12:53 pm, Christophe Grand  wrote:
>
> > > >> > > > Hi Gabi!
>
> > > >> > > > Can you tell us more about your problem, what do those deeply 
> > > >> > > > nested
> > > >> > > > vectors represent and how are you going to update them? (are all
> > > >> > > > updates batched in one part of your program?)
>
> > > >> > > > With transients current implementation you can't write an 
> > > >> > > > efficient update-in!
>
> > > >> > > > Christophe
>
> > > >> > > > On Wed, Jan 20, 2010 at 9:15 AM, Gabi  
> > > >> > > > wrote:
> > > >> > > > > Guys, I really need your expertise here.
> > > >> > > > > I have lots of deeply nested vectors, which i need to 
> > > >> > > > > manipulate
> > > >> > > > > frequently (thousands of times)
> > > >> > > > > What is the most effective way to do this ?
>
> > > >> > > > > On Jan 17, 4:27 pm, Gabi  wrote:
> > > >> > > > >> Right. I thought that transient performing deep 
> > > >> > > > >> 'transientivity'.
> > > >> > > > >> Here is a fixed version. It takes a regular coll converts 
> > > >> > > > >> whatever it
> > > >> > > > >> can to transient and update the stuff.
> > > >> > > > >> The problem is that doing persistent!(assoc!(transient m)) on 
> >

Re: update-in! (?)

2010-01-20 Thread Gabi
I posted a question on SO about it. Interesting discussion:
http://stackoverflow.com/questions/2102606/algorithm-to-implement-non-binary-trees-using-1-dimensional-vector

On Jan 20, 5:39 pm, Christophe Grand  wrote:
> I concur: a map (or a sorted map if you need to emulate access to a
> subtree) can be an option.
>
> [[1 2] [3 4]] is represented by {[0 0] 1, [0 1] 2, [1 0] 3, [1 1] 4}
>
>
>
> On Wed, Jan 20, 2010 at 4:24 PM, Sean Devlin  wrote:
> > How about a sorted set w/ a custom comparator?  Of course, this rules
> > out transients, but maybe the flatness will make up for it?
>
> > On Jan 20, 10:15 am, Gabi  wrote:
> >> I need to add/delete much more frequently than just updating
> >> actually.
>
> >> On Jan 20, 4:59 pm, Sean Devlin  wrote:
>
> >> > Gabi,
> >> > A similar technique is used with sparse matrices.  You usually have
> >> > severals arrays, one for the non-zero elements, and another one for
> >> > indexing the column and a third for indexing the rows.
>
> >> >http://pasadena.wr.usgs.gov/office/baagaard/research/papers/thesis/fi...
>
> >> > This should be fast as long as you're only updating.  If you're
> >> > inserting/deleting, you might be able to get away with using a
> >> > collection of 1D trees.
>
> >> > Sean
>
> >> > On Jan 20, 9:18 am, Gabi  wrote:
>
> >> > > These vectors represent trees which need to updated very frequently.
> >> > > So If there was an efficient way to use transients to represent
> >> > > transient trees the whole process would be much more efficient (so
> >> > > each update to a tree would be done in place instead of creating new
> >> > > one.) As discussed above, naive usage of transients won't help.
> >> > > Another approach would be implement in Java, but I wish there would
> >> > > some way to achieve this directly from Clojure.
> >> > > Now that I think about it, maybe the solution is to represent the tree
> >> > > as one dimensional vector instead of nested one (any good clojure
> >> > > algorithm for this ? Representing and traversing non binary trees as
> >> > > one dimensional vector?)
>
> >> > > Jan 20, 12:53 pm, Christophe Grand  wrote:
>
> >> > > > Hi Gabi!
>
> >> > > > Can you tell us more about your problem, what do those deeply nested
> >> > > > vectors represent and how are you going to update them? (are all
> >> > > > updates batched in one part of your program?)
>
> >> > > > With transients current implementation you can't write an efficient 
> >> > > > update-in!
>
> >> > > > Christophe
>
> >> > > > On Wed, Jan 20, 2010 at 9:15 AM, Gabi  wrote:
> >> > > > > Guys, I really need your expertise here.
> >> > > > > I have lots of deeply nested vectors, which i need to manipulate
> >> > > > > frequently (thousands of times)
> >> > > > > What is the most effective way to do this ?
>
> >> > > > > On Jan 17, 4:27 pm, Gabi  wrote:
> >> > > > >> Right. I thought that transient performing deep 'transientivity'.
> >> > > > >> Here is a fixed version. It takes a regular coll converts 
> >> > > > >> whatever it
> >> > > > >> can to transient and update the stuff.
> >> > > > >> The problem is that doing persistent!(assoc!(transient m)) on each
> >> > > > >> level probably misses the whole point of performance.
> >> > > > >> So while it work, it probably slower than the regular update-in.
> >> > > > >> I need a better solution.
>
> >> > > > >> (defn update-in!!
> >> > > > >>   "modified version of core/update-in that works on, and return
> >> > > > >> transiants"
> >> > > > >>   ([m [k & ks] f & args]
> >> > > > >>    (if ks
> >> > > > >>      (persistent!(assoc! (transient m) k (apply update-in!! (get 
> >> > > > >> m k)
> >> > > > >> ks f args)))
> >> > > > >>      (persistent!(assoc! (transient m) k (apply f (get m k) 
> >> > > > >> args))
>
> >> > > > >> On Jan 17, 3:57 pm, Chouser  wro

Re: update-in! (?)

2010-01-20 Thread Gabi
Can you elaborate more ? How can trees be represented in sorted sets?

On Jan 20, 5:24 pm, Sean Devlin  wrote:
> How about a sorted set w/ a custom comparator?  Of course, this rules
> out transients, but maybe the flatness will make up for it?
>
> On Jan 20, 10:15 am, Gabi  wrote:
>
> > I need to add/delete much more frequently than just updating
> > actually.
>
> > On Jan 20, 4:59 pm, Sean Devlin  wrote:
>
> > > Gabi,
> > > A similar technique is used with sparse matrices.  You usually have
> > > severals arrays, one for the non-zero elements, and another one for
> > > indexing the column and a third for indexing the rows.
>
> > >http://pasadena.wr.usgs.gov/office/baagaard/research/papers/thesis/fi...
>
> > > This should be fast as long as you're only updating.  If you're
> > > inserting/deleting, you might be able to get away with using a
> > > collection of 1D trees.
>
> > > Sean
>
> > > On Jan 20, 9:18 am, Gabi  wrote:
>
> > > > These vectors represent trees which need to updated very frequently.
> > > > So If there was an efficient way to use transients to represent
> > > > transient trees the whole process would be much more efficient (so
> > > > each update to a tree would be done in place instead of creating new
> > > > one.) As discussed above, naive usage of transients won't help.
> > > > Another approach would be implement in Java, but I wish there would
> > > > some way to achieve this directly from Clojure.
> > > > Now that I think about it, maybe the solution is to represent the tree
> > > > as one dimensional vector instead of nested one (any good clojure
> > > > algorithm for this ? Representing and traversing non binary trees as
> > > > one dimensional vector?)
>
> > > > Jan 20, 12:53 pm, Christophe Grand  wrote:
>
> > > > > Hi Gabi!
>
> > > > > Can you tell us more about your problem, what do those deeply nested
> > > > > vectors represent and how are you going to update them? (are all
> > > > > updates batched in one part of your program?)
>
> > > > > With transients current implementation you can't write an efficient 
> > > > > update-in!
>
> > > > > Christophe
>
> > > > > On Wed, Jan 20, 2010 at 9:15 AM, Gabi  wrote:
> > > > > > Guys, I really need your expertise here.
> > > > > > I have lots of deeply nested vectors, which i need to manipulate
> > > > > > frequently (thousands of times)
> > > > > > What is the most effective way to do this ?
>
> > > > > > On Jan 17, 4:27 pm, Gabi  wrote:
> > > > > >> Right. I thought that transient performing deep 'transientivity'.
> > > > > >> Here is a fixed version. It takes a regular coll converts whatever 
> > > > > >> it
> > > > > >> can to transient and update the stuff.
> > > > > >> The problem is that doing persistent!(assoc!(transient m)) on each
> > > > > >> level probably misses the whole point of performance.
> > > > > >> So while it work, it probably slower than the regular update-in.
> > > > > >> I need a better solution.
>
> > > > > >> (defn update-in!!
> > > > > >>   "modified version of core/update-in that works on, and return
> > > > > >> transiants"
> > > > > >>   ([m [k & ks] f & args]
> > > > > >>    (if ks
> > > > > >>      (persistent!(assoc! (transient m) k (apply update-in!! (get m 
> > > > > >> k)
> > > > > >> ks f args)))
> > > > > >>      (persistent!(assoc! (transient m) k (apply f (get m k) 
> > > > > >> args))
>
> > > > > >> On Jan 17, 3:57 pm, Chouser  wrote:
>
> > > > > >> > On Sun, Jan 17, 2010 at 8:25 AM, Gabi  
> > > > > >> > wrote:
>
> > > > > >> > >> user=> (persistent!(update-in!(transient v) [0] reverse))
>
> > > > > >> > > Forgot to mention that v in the example is defined to  [[1 2] 
> > > > > >> > > [3 4]]
>
> > > > > >> > So you've got a transient vector of persistent vectors of
> > > > > >> > numbers.  The problem is your update-in! then calls asso

Re: update-in! (?)

2010-01-20 Thread Gabi
I need to add/delete much more frequently than just updating
actually.


On Jan 20, 4:59 pm, Sean Devlin  wrote:
> Gabi,
> A similar technique is used with sparse matrices.  You usually have
> severals arrays, one for the non-zero elements, and another one for
> indexing the column and a third for indexing the rows.
>
> http://pasadena.wr.usgs.gov/office/baagaard/research/papers/thesis/fi...
>
> This should be fast as long as you're only updating.  If you're
> inserting/deleting, you might be able to get away with using a
> collection of 1D trees.
>
> Sean
>
> On Jan 20, 9:18 am, Gabi  wrote:
>
> > These vectors represent trees which need to updated very frequently.
> > So If there was an efficient way to use transients to represent
> > transient trees the whole process would be much more efficient (so
> > each update to a tree would be done in place instead of creating new
> > one.) As discussed above, naive usage of transients won't help.
> > Another approach would be implement in Java, but I wish there would
> > some way to achieve this directly from Clojure.
> > Now that I think about it, maybe the solution is to represent the tree
> > as one dimensional vector instead of nested one (any good clojure
> > algorithm for this ? Representing and traversing non binary trees as
> > one dimensional vector?)
>
> > Jan 20, 12:53 pm, Christophe Grand  wrote:
>
> > > Hi Gabi!
>
> > > Can you tell us more about your problem, what do those deeply nested
> > > vectors represent and how are you going to update them? (are all
> > > updates batched in one part of your program?)
>
> > > With transients current implementation you can't write an efficient 
> > > update-in!
>
> > > Christophe
>
> > > On Wed, Jan 20, 2010 at 9:15 AM, Gabi  wrote:
> > > > Guys, I really need your expertise here.
> > > > I have lots of deeply nested vectors, which i need to manipulate
> > > > frequently (thousands of times)
> > > > What is the most effective way to do this ?
>
> > > > On Jan 17, 4:27 pm, Gabi  wrote:
> > > >> Right. I thought that transient performing deep 'transientivity'.
> > > >> Here is a fixed version. It takes a regular coll converts whatever it
> > > >> can to transient and update the stuff.
> > > >> The problem is that doing persistent!(assoc!(transient m)) on each
> > > >> level probably misses the whole point of performance.
> > > >> So while it work, it probably slower than the regular update-in.
> > > >> I need a better solution.
>
> > > >> (defn update-in!!
> > > >>   "modified version of core/update-in that works on, and return
> > > >> transiants"
> > > >>   ([m [k & ks] f & args]
> > > >>    (if ks
> > > >>      (persistent!(assoc! (transient m) k (apply update-in!! (get m k)
> > > >> ks f args)))
> > > >>      (persistent!(assoc! (transient m) k (apply f (get m k) args))
>
> > > >> On Jan 17, 3:57 pm, Chouser  wrote:
>
> > > >> > On Sun, Jan 17, 2010 at 8:25 AM, Gabi  wrote:
>
> > > >> > >> user=> (persistent!(update-in!(transient v) [0] reverse))
>
> > > >> > > Forgot to mention that v in the example is defined to  [[1 2] [3 
> > > >> > > 4]]
>
> > > >> > So you've got a transient vector of persistent vectors of
> > > >> > numbers.  The problem is your update-in! then calls assoc! on
> > > >> > each level, but of course assoc! on the inner persistent vector
> > > >> > fails.
>
> > > >> > You either need to make the inner vectors transient (and then
> > > >> > call persist! on them when you're done) or use assoc! only at the
> > > >> > outer level.
>
> > > >> > --Chouserhttp://joyofclojure.com/
>
> > > > --
> > > > 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 moderated - please be patient with 
> > > > your first post.
> > > > To unsubscribe from this group, send email to
> > > > clojure+unsubscr...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/clojure?hl=en
>
> > > --
> > > Professional:http://cgrand.net/(fr)
> > > On Clojure:http://clj-me.cgrand.net/(en)
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: update-in! (?)

2010-01-20 Thread Gabi
These vectors represent trees which need to updated very frequently.
So If there was an efficient way to use transients to represent
transient trees the whole process would be much more efficient (so
each update to a tree would be done in place instead of creating new
one.) As discussed above, naive usage of transients won't help.
Another approach would be implement in Java, but I wish there would
some way to achieve this directly from Clojure.
Now that I think about it, maybe the solution is to represent the tree
as one dimensional vector instead of nested one (any good clojure
algorithm for this ? Representing and traversing non binary trees as
one dimensional vector?)


Jan 20, 12:53 pm, Christophe Grand  wrote:
> Hi Gabi!
>
> Can you tell us more about your problem, what do those deeply nested
> vectors represent and how are you going to update them? (are all
> updates batched in one part of your program?)
>
> With transients current implementation you can't write an efficient update-in!
>
> Christophe
>
>
>
> On Wed, Jan 20, 2010 at 9:15 AM, Gabi  wrote:
> > Guys, I really need your expertise here.
> > I have lots of deeply nested vectors, which i need to manipulate
> > frequently (thousands of times)
> > What is the most effective way to do this ?
>
> > On Jan 17, 4:27 pm, Gabi  wrote:
> >> Right. I thought that transient performing deep 'transientivity'.
> >> Here is a fixed version. It takes a regular coll converts whatever it
> >> can to transient and update the stuff.
> >> The problem is that doing persistent!(assoc!(transient m)) on each
> >> level probably misses the whole point of performance.
> >> So while it work, it probably slower than the regular update-in.
> >> I need a better solution.
>
> >> (defn update-in!!
> >>   "modified version of core/update-in that works on, and return
> >> transiants"
> >>   ([m [k & ks] f & args]
> >>    (if ks
> >>      (persistent!(assoc! (transient m) k (apply update-in!! (get m k)
> >> ks f args)))
> >>      (persistent!(assoc! (transient m) k (apply f (get m k) args))
>
> >> On Jan 17, 3:57 pm, Chouser  wrote:
>
> >> > On Sun, Jan 17, 2010 at 8:25 AM, Gabi  wrote:
>
> >> > >> user=> (persistent!(update-in!(transient v) [0] reverse))
>
> >> > > Forgot to mention that v in the example is defined to  [[1 2] [3 4]]
>
> >> > So you've got a transient vector of persistent vectors of
> >> > numbers.  The problem is your update-in! then calls assoc! on
> >> > each level, but of course assoc! on the inner persistent vector
> >> > fails.
>
> >> > You either need to make the inner vectors transient (and then
> >> > call persist! on them when you're done) or use assoc! only at the
> >> > outer level.
>
> >> > --Chouserhttp://joyofclojure.com/
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
>
> --
> Professional:http://cgrand.net/(fr)
> On Clojure:http://clj-me.cgrand.net/(en)
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: update-in! (?)

2010-01-20 Thread Gabi
Guys, I really need your expertise here.
I have lots of deeply nested vectors, which i need to manipulate
frequently (thousands of times)
What is the most effective way to do this ?

On Jan 17, 4:27 pm, Gabi  wrote:
> Right. I thought that transient performing deep 'transientivity'.
> Here is a fixed version. It takes a regular coll converts whatever it
> can to transient and update the stuff.
> The problem is that doing persistent!(assoc!(transient m)) on each
> level probably misses the whole point of performance.
> So while it work, it probably slower than the regular update-in.
> I need a better solution.
>
> (defn update-in!!
>   "modified version of core/update-in that works on, and return
> transiants"
>   ([m [k & ks] f & args]
>    (if ks
>      (persistent!(assoc! (transient m) k (apply update-in!! (get m k)
> ks f args)))
>      (persistent!(assoc! (transient m) k (apply f (get m k) args))
>
> On Jan 17, 3:57 pm, Chouser  wrote:
>
> > On Sun, Jan 17, 2010 at 8:25 AM, Gabi  wrote:
>
> > >> user=> (persistent!(update-in!(transient v) [0] reverse))
>
> > > Forgot to mention that v in the example is defined to  [[1 2] [3 4]]
>
> > So you've got a transient vector of persistent vectors of
> > numbers.  The problem is your update-in! then calls assoc! on
> > each level, but of course assoc! on the inner persistent vector
> > fails.
>
> > You either need to make the inner vectors transient (and then
> > call persist! on them when you're done) or use assoc! only at the
> > outer level.
>
> > --Chouserhttp://joyofclojure.com/
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Why "recur"?

2010-01-17 Thread Gabi
I was wondering about that myself but was too embarrassed to ask :)

On Jan 17, 8:39 am, itsnotvalid  wrote:
> Just started learning Clojure a day ago with Stuart's book I found
> that Clojure doesn't do tail recursion optimization, not at least for
> the most simplest form. Instead the call must be made to recur instead
> of the function itself.
>
> However in the more-or-less-the-same-camp Scala does such optimization
> (not for the case with ta which Clojure's FAQ claims that "if JVM
> doesn't we can't do anything". I don't know how exactly Scala does
> this however using special form "recur" is very ugly and makes quite a
> bit of functional programming very pointless (just look at the famous
> 'fib'.)
>
> Or I am just plain wrong.
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: update-in! (?)

2010-01-17 Thread Gabi
Right. I thought that transient performing deep 'transientivity'.
Here is a fixed version. It takes a regular coll converts whatever it
can to transient and update the stuff.
The problem is that doing persistent!(assoc!(transient m)) on each
level probably misses the whole point of performance.
So while it work, it probably slower than the regular update-in.
I need a better solution.

(defn update-in!!
  "modified version of core/update-in that works on, and return
transiants"
  ([m [k & ks] f & args]
   (if ks
 (persistent!(assoc! (transient m) k (apply update-in!! (get m k)
ks f args)))
 (persistent!(assoc! (transient m) k (apply f (get m k) args))

On Jan 17, 3:57 pm, Chouser  wrote:
> On Sun, Jan 17, 2010 at 8:25 AM, Gabi  wrote:
>
> >> user=> (persistent!(update-in!(transient v) [0] reverse))
>
> > Forgot to mention that v in the example is defined to  [[1 2] [3 4]]
>
> So you've got a transient vector of persistent vectors of
> numbers.  The problem is your update-in! then calls assoc! on
> each level, but of course assoc! on the inner persistent vector
> fails.
>
> You either need to make the inner vectors transient (and then
> call persist! on them when you're done) or use assoc! only at the
> outer level.
>
> --Chouserhttp://joyofclojure.com/
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: update-in! (?)

2010-01-17 Thread Gabi
Forgot to mention that v in the example is defined to  [[1 2] [3 4]]

On Jan 17, 3:19 pm, Gabi  wrote:
> I really needed an update-in! version that works on transients. I
> couldn't find one so I just modified the original update-in core (just
> replaced "assoc" "assoc!"):
>
> (defn update-in!
>   "modified version of core/update-in that works on, and return
> transients"
>   ([m [k & ks] f & args]
>    (if ks
>      (assoc! m k (apply update-in! (get m k) ks f args))
>      (assoc! m k (apply f (get m k) args)
>
> user=> (persistent!(update-in!(transient v) [0] reverse))
> [(2 1) [3 4]]
>
> BUT when using nested paths, it fails:
>
> user=>(persistent!(update-in!(transient v) [0 0] inc))
> java.lang.ClassCastException: clojure.lang.PersistentVector cannot be
> cast to clojure.lang.ITransientAssociative
>
> Any idea how to solve this?
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

update-in! (?)

2010-01-17 Thread Gabi
I really needed an update-in! version that works on transients. I
couldn't find one so I just modified the original update-in core (just
replaced "assoc" "assoc!"):

(defn update-in!
  "modified version of core/update-in that works on, and return
transients"
  ([m [k & ks] f & args]
   (if ks
 (assoc! m k (apply update-in! (get m k) ks f args))
 (assoc! m k (apply f (get m k) args)


user=> (persistent!(update-in!(transient v) [0] reverse))
[(2 1) [3 4]]

BUT when using nested paths, it fails:

user=>(persistent!(update-in!(transient v) [0 0] inc))
java.lang.ClassCastException: clojure.lang.PersistentVector cannot be
cast to clojure.lang.ITransientAssociative

Any idea how to solve this?
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What's the idiomatic way to parse a binding form

2010-01-12 Thread Gabi
I only need the simple way. To get a vector and to treats it as a set
of key/vals.
So, Jarkko's solution is what I was looking for. (apply hash-map
keyvals)

On Jan 12, 5:49 pm, samppi  wrote:
> Do you also want the binding to act like let's, with unpacking of
> vectors and maps?
>
> If so, there's no public function that I know of that's set apart for
> doing this—are you trying to do this in a function or a macro? If
> you're creating a macro, then it's easy: just splice the binding form
> into a let. But if you're creating a function (though why you would
> need to, I can't imagine—since you're creating symbol bindings
> anyway), I'm not sure how you would deal with it, but I'm sure there
> is a way.
>
> But then again, if you don't want let's destructing, then as Jarkko
> Oranen said, partition is probably what you want.
>
> On Jan 12, 4:12 am, Jarkko Oranen  wrote:
>
> > On Jan 12, 11:08 am, Gabi  wrote:
>
> > > What's the idiomatic Clojure way for extracting values/keys from a
> > > binding form vector [key1 val1 key2 val2..] ?
>
> > I suppose that depends on what you want, but:
>
> > (apply hash-map keyvals) to make a map or
> > (map first (partition 2 keyvals)) & (map second (partition 2 keyvals))
>
> > --
> > Jarkko
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

What's the idiomatic way to parse a binding form

2010-01-12 Thread Gabi
What's the idiomatic Clojure way for extracting values/keys from a
binding form vector [key1 val1 key2 val2..] ?


-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommendation for Clojure Indentation tool

2010-01-09 Thread Gabi
Maybe you can post here an example code of how you used it ? Maybe I
missed something?

On Jan 9, 10:38 pm, Laurent PETIT  wrote:
> Weird, it used to work for me when I tested it. And it appears it also
> worked for some people on the thread ...
>
> 2010/1/9 Gabi :
>
> > Yes. Didn't work. Even after fixing a bug in it (complained about
> > Character/isWhitespace ) it produced garbage
>
> > On Jan 9, 3:00 pm, Laurent PETIT  wrote:
> >> Have you tried what I wrote in my above post ?
>
> >> 2010/1/9 Gabi :
>
> >> > I really hate emacs. And the solution in
> >> >http://www.google.com/url?sa=D&q=http://groups.google.com/group/cloju...
> >> > doesn't work
>
> >> > Any other way to format lisp/clojure ?
>
> >> > On Dec 23 2009, 7:22 pm, Stefan Kamphausen 
> >> > wrote:
> >> >> Hi,
>
> >> >> On Dec 22, 11:48 am, Gabi  wrote:
>
> >> >> > I need a simple command-line tool to indent Clojure source files.
> >> >> > Any recommendation ?
>
> >> >> there was a post to a ruby script for some OSX editor which provided
> >> >> the Clojure indentation by calling emacs in batch-mode.  Unfortunately
> >> >> I can't find it anymore.  Sorry.  Anyone else remember?
>
> >> >> Regards,
> >> >> Stefan
>
> >> > --
> >> > 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 moderated - please be patient with 
> >> > your first post.
> >> > To unsubscribe from this group, send email to
> >> > clojure+unsubscr...@googlegroups.com
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/clojure?hl=en
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommendation for Clojure Indentation tool

2010-01-09 Thread Gabi
Just found an easy and stupid way. Using Kate editor:

1, Tools->indentation->Lisp
2. Select the whole text and do Tools ->Align



On Jan 9, 10:17 pm, Gabi  wrote:
> Yes. Didn't work. Even after fixing a bug in it (complained about
> Character/isWhitespace ) it produced garbage
>
> On Jan 9, 3:00 pm, Laurent PETIT  wrote:
>
> > Have you tried what I wrote in my above post ?
>
> > 2010/1/9 Gabi :
>
> > > I really hate emacs. And the solution in
> > >http://www.google.com/url?sa=D&q=http://groups.google.com/group/cloju...
> > > doesn't work
>
> > > Any other way to format lisp/clojure ?
>
> > > On Dec 23 2009, 7:22 pm, Stefan Kamphausen 
> > > wrote:
> > >> Hi,
>
> > >> On Dec 22, 11:48 am, Gabi  wrote:
>
> > >> > I need a simple command-line tool to indent Clojure source files.
> > >> > Any recommendation ?
>
> > >> there was a post to a ruby script for some OSX editor which provided
> > >> the Clojure indentation by calling emacs in batch-mode.  Unfortunately
> > >> I can't find it anymore.  Sorry.  Anyone else remember?
>
> > >> Regards,
> > >> Stefan
>
> > > --
> > > 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 moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommendation for Clojure Indentation tool

2010-01-09 Thread Gabi
Yes. Didn't work. Even after fixing a bug in it (complained about
Character/isWhitespace ) it produced garbage

On Jan 9, 3:00 pm, Laurent PETIT  wrote:
> Have you tried what I wrote in my above post ?
>
> 2010/1/9 Gabi :
>
> > I really hate emacs. And the solution in
> >http://www.google.com/url?sa=D&q=http://groups.google.com/group/cloju...
> > doesn't work
>
> > Any other way to format lisp/clojure ?
>
> > On Dec 23 2009, 7:22 pm, Stefan Kamphausen 
> > wrote:
> >> Hi,
>
> >> On Dec 22, 11:48 am, Gabi  wrote:
>
> >> > I need a simple command-line tool to indent Clojure source files.
> >> > Any recommendation ?
>
> >> there was a post to a ruby script for some OSX editor which provided
> >> the Clojure indentation by calling emacs in batch-mode.  Unfortunately
> >> I can't find it anymore.  Sorry.  Anyone else remember?
>
> >> Regards,
> >> Stefan
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommendation for Clojure Indentation tool

2010-01-09 Thread Gabi
I really hate emacs. And the solution in
http://www.google.com/url?sa=D&q=http://groups.google.com/group/clojure/browse_thread/thread/6a16bb89340f46d8/fb03dffa410e919a%3Flnk%3Dgst%26q%3Dharrop%2Bindent%23fb03dffa410e919a&usg=AFQjCNFAyiZOBGMdhoXnFe1UaFrJQTgGUg
doesn't work

Any other way to format lisp/clojure ?

On Dec 23 2009, 7:22 pm, Stefan Kamphausen 
wrote:
> Hi,
>
> On Dec 22, 11:48 am, Gabi  wrote:
>
> > I need a simple command-line tool to indent Clojure source files.
> > Any recommendation ?
>
> there was a post to a ruby script for some OSX editor which provided
> the Clojure indentation by calling emacs in batch-mode.  Unfortunately
> I can't find it anymore.  Sorry.  Anyone else remember?
>
> Regards,
> Stefan
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommended JVM flags for Clojure

2010-01-08 Thread Gabi
Ok guys,

After trying all your suggestions, here is the combination that worked
best for me (in the order of their impact solving the problem):

JVM_FLAGS="-server  \
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode \
-XX:+UseCompressedOops \
-XX:+DoEscapeAnalysis \
-XX:+UseBiasedLocking \
-XX:PermSize=64M \
-XX:MaxPermSize=256M \
-Xmx2g"


Now my app consumes  ~500M of resident memory, but at least does not
crash and performance does not deteriorate.

BTW, I also tried the 'new' branch suggested . Didn't see any
noticeable effect.

On Jan 8, 4:40 am, Seth  wrote:
> Hi Gabi,
>
> This may not be useful, but have you tried running the Clojure new
> branch? Rich implemented fine-grained locals clearing on the new
> branch, and it helps avoid holding onto unused data accidentally.
>
> http://groups.google.com/group/clojure/browse_thread/thread/14baed8f2...
>
> Seth
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recommended JVM flags for Clojure

2010-01-07 Thread Gabi
Thanks I'll try those flags. I indeed use 64 bits

On Jan 7, 6:47 pm, kyle smith  wrote:
> First, make sure you have -server. If you can spare more heap, use -
> Xmx1g . If you're on a 64bit jvm, -XX:+UseCompressedOops adds a
> significant boost. A flag that helps quite a bit is -XX:
> +DoEscapeAnalysis .  Finally, if you want to play around with the JIT
> threshold, use -XX:CompileThreshold=n , where n defaults to 1.
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Recommended JVM flags for Clojure

2010-01-07 Thread Gabi
Hello fellow Clojurians,

I got lots of "java.lang.OutOfMemoryError: GC overhead limit exceeded
" exceptions ,and after a short investigation added the following
flags (JVM 1.6.0_17):
-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:
+CMSIncrementalPacing

These flags seems to solve the problem, but I am interested in your
experience and best practices regarding JVM flags in clojure.

I know it really depends on the type of the application, but it seems
to me that the gc is working really hard under Clojure (I cannot prove
it, this is just an impression)

Gabi





-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: How to add extend print-method without screwing up ?

2010-01-05 Thread Gabi
Yes. I guess you have a point. Maybe I just wanted too much out of it.
This think could be solved easily if defmethod supported hierarchy as
arg (or in meta).
But on the other hand, such feature would make it very easy to make a
total mess..



On Jan 5, 11:59 pm, Laurent PETIT  wrote:
> Multi-methods can be extended ... to the extent of what their
> dispatch-function defines.
>
> So for what you want to work, you should have this notion of "from
> where is the multi-method called" wired in the dispatch function.
> Imagineyou could redefine the dispatch function (which you can not for
> print-method, or this would be very hackish I guess). Even there,
> you'll have to solve the "how does the dispatch method know from which
> namespace the multimethod is called ?" ...). Generally, dispatch
> methods will work on the arguments of the multi-method. Surely, they
> could also work by doing introspection of the call stack by hooking
> into clojure internals, and also you could make them work differently
> by having them inspect global variables ... huck !!!
>
> What you want isn't even easily solved by OOP like in javascript,
> where you can change every method implementation of every object,
> because you would like the method implementation to be chosen
> depending on the caller of the method, not just the callee or a
> function of the other arguments of the method ...
>
> HTH,
>
> --
> Laurent
>
> 2010/1/5 Gabi :
>
> > Hmm.. I hoped I could avoid this.  Multi-methods should be extended,
> > not copied and then extended :)
> > But if there is no other way, I probably settle for this cumbersome
> > solution..
>
> > On Jan 5, 11:21 pm, Laurent PETIT  wrote:
> >> How about creating your own print-method multimethod in a lib of your
> >> own, and in your libs, excluding clojure.core/print-method and
> >> importing your-lib/print-method instead.
>
> >> Then, in your-lib, make the default print-method invocation just call
> >> clojure.core/print-method, create your own private hierarchy, and
> >> provide defmethods for those types you want to provide with your own
> >> implementation of defmethod ...
>
> >> Cant' think of something better, for now ...
>
> >> HTH,
>
> >> --
> >> Laurent
>
> >> 2010/1/5 Gabi :
>
> >> > Hi
> >> > I am trying to extend Clojures' print-method using defmethod for a
> >> > library I develop.:
> >> > How can I do this without affecting users of my lib (i want only my
> >> > lib to be affected )?
>
> >> > (derive clojure.lang.Fn ::fn)
> >> > (prefer-method print-method ::fn  java.lang.Object)
>
> >> > (defmethod print-method ::fn
> >> >    [o w]
> >> >   (.write w "Some Fn")
>
> >> > This is quite nice, but I would like to use a private hierarchy for
> >> > the above, but cant. (print-method is defined on global hierarchy)
> >> > What should I do ?
>
> >> > --
> >> > 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 moderated - please be patient with 
> >> > your first post.
> >> > To unsubscribe from this group, send email to
> >> > clojure+unsubscr...@googlegroups.com
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/clojure?hl=en
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: How to add extend print-method without screwing up ?

2010-01-05 Thread Gabi
Hmm.. I hoped I could avoid this.  Multi-methods should be extended,
not copied and then extended :)
But if there is no other way, I probably settle for this cumbersome
solution..


On Jan 5, 11:21 pm, Laurent PETIT  wrote:
> How about creating your own print-method multimethod in a lib of your
> own, and in your libs, excluding clojure.core/print-method and
> importing your-lib/print-method instead.
>
> Then, in your-lib, make the default print-method invocation just call
> clojure.core/print-method, create your own private hierarchy, and
> provide defmethods for those types you want to provide with your own
> implementation of defmethod ...
>
> Cant' think of something better, for now ...
>
> HTH,
>
> --
> Laurent
>
> 2010/1/5 Gabi :
>
> > Hi
> > I am trying to extend Clojures' print-method using defmethod for a
> > library I develop.:
> > How can I do this without affecting users of my lib (i want only my
> > lib to be affected )?
>
> > (derive clojure.lang.Fn ::fn)
> > (prefer-method print-method ::fn  java.lang.Object)
>
> > (defmethod print-method ::fn
> >    [o w]
> >   (.write w "Some Fn")
>
> > This is quite nice, but I would like to use a private hierarchy for
> > the above, but cant. (print-method is defined on global hierarchy)
> > What should I do ?
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

How to add extend print-method without screwing up ?

2010-01-05 Thread Gabi
Hi
I am trying to extend Clojures' print-method using defmethod for a
library I develop.:
How can I do this without affecting users of my lib (i want only my
lib to be affected )?

(derive clojure.lang.Fn ::fn)
(prefer-method print-method ::fn  java.lang.Object)

(defmethod print-method ::fn
[o w]
   (.write w "Some Fn")

This is quite nice, but I would like to use a private hierarchy for
the above, but cant. (print-method is defined on global hierarchy)
What should I do ?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-05 Thread Gabi
I think you should do "(binding [*print-dup* true] (pr-str value).."
instead of  just (pr-str value) in the encode-value function. (line 20
in redis_memo.clj)

On Jan 4, 2:55 pm, Steve Purcell  wrote:
> Read the code I posted in this thread and put up on github after you 
> expressed interest.
>
> That's part of what it does, using the reader/printer representation.
>
> Alternatives would include standard Java binary serialisation or 3rd party 
> libraries (Hessian/Burlap?).
>
> -Steve
>
> On 4 Jan 2010, at 12:15, Gabi wrote:
>
> > What if I wanted to use Redis just persist binary (serialized) clojure
> > objects ?
> > What's the easiest (and fastest) way to serialize/de-serialize vectors
> > or lists in Clojure ? (so the can stored as blobs in Redis)
>
> > On Jan 4, 12:59 pm, Gabi  wrote:
> >> Maybe, though I would avoid distributed transactions as much as
> >> possible. They are complex and slow creatures.
>
> >> On Jan 4, 12:51 pm, Shantanu Kumar  wrote:
>
> >>> On Jan 2, 5:12 am, Gabi  wrote:
>
> >>>> I am interested in the idea: Completely stateless set of Clojure nodes
> >>>> (on many machines), operating on a central state stored in some
> >>>> datastore.
> >>>> If transactions could be managed somehow, I think it would be very
> >>>> compelling model for many applications.
>
> >>> Do you mean distributed transactions?
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-04 Thread Gabi
What if I wanted to use Redis just persist binary (serialized) clojure
objects ?
What's the easiest (and fastest) way to serialize/de-serialize vectors
or lists in Clojure ? (so the can stored as blobs in Redis)

On Jan 4, 12:59 pm, Gabi  wrote:
> Maybe, though I would avoid distributed transactions as much as
> possible. They are complex and slow creatures.
>
> On Jan 4, 12:51 pm, Shantanu Kumar  wrote:
>
> > On Jan 2, 5:12 am, Gabi  wrote:
>
> > > I am interested in the idea: Completely stateless set of Clojure nodes
> > > (on many machines), operating on a central state stored in some
> > > datastore.
> > > If transactions could be managed somehow, I think it would be very
> > > compelling model for many applications.
>
> > Do you mean distributed transactions?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-04 Thread Gabi
Maybe, though I would avoid distributed transactions as much as
possible. They are complex and slow creatures.




On Jan 4, 12:51 pm, Shantanu Kumar  wrote:
> On Jan 2, 5:12 am, Gabi  wrote:
>
> > I am interested in the idea: Completely stateless set of Clojure nodes
> > (on many machines), operating on a central state stored in some
> > datastore.
> > If transactions could be managed somehow, I think it would be very
> > compelling model for many applications.
>
> Do you mean distributed transactions?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-04 Thread Gabi
How about congomongo (http://github.com/somnium/congomongo) ?
Have anybody used it ? Seems good choice for storing state in central
location..

On Jan 4, 2:40 am, Tom Hicks  wrote:
> Have you looked at Neo4J? I have no experience with it but
> someone in the forum just announced a Clojure wrapper for it:
>
> http://groups.google.com/group/clojure/browse_thread/thread/9628c6227...
>    cheers,
>     -t
>
> On Jan 1, 2:07 pm, Julian Morrison  wrote:
>
> > I've just recently been poking around these NoSQLs investigating their
> > features, so...
>
> > Redis has limited data structures - flat un-nested lists and sets, and
> > plain strings. It doesn't have sets exactly - just keys and values.
> > Nothing nested at all, unless you serialize to strings. No indexes,
> > although you can hack up your own.
>
> > To be honest, Redis isn't that impressive versus what's in Clojure
> > already. It's an in-memory DB (so it's not much different from ref
> > +dosync) and it intermittently spits a snapshot to disk. If you can
> > live with an in-process DB, you could copy (and exceed) its features
> > including snapshot saving in a page of pure Clojure code, and beat it
> > on speed too.
>
> > Contrast MongoDB: slower because it bothers to save things, but still
> > around twice as fast as MySQL and much faster than CouchDB (cite: the
> > benchmarks page). Arbitrarily nested collections, indexes, atomic
> > updates (in place operations like inc and append, or atomic compare-
> > and-set), JSON syntax, typed data, replication (built in) and sharding
> > (via a broker process).
>
> > (MongoDB downsides: it grows files in a very greedy way to try and
> > minimize data fragmentation, and it needs a 64bit machine to store
> > more than about 2Gb.)
>
> > On Dec 30 2009, 11:52 am, Gabi  wrote:
>
> > > On first look, Redis and Clojure seems to be a perfect match. They
> > > both handle sets and maps efficiently. If one could find an easy way
> > > to store and retrieve Clojure data structures to Redis (even a small
> > > subset- just a list or a set), a distributed clojure app could be very
> > > easy (and effective?) thing to do - The stateless Clojure nodes would
> > > share and operate on the same central data structure which is stored
> > > in Redis). What do you thing ? Is it worth investigating further?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
But that does not exclude the fact that sorted-vec-2 is about %75
times faster than sort

On Jan 3, 11:26 pm, Gabi  wrote:
> It turns out I run the client version.
> When running the server version (-server) the performance of sort is 4
> times better.
>
> On Jan 3, 11:20 pm, Gabi  wrote:
>
> > "1.6.0_17" .It doesn't support this flag:
> > Unrecognized VM option '+DoEscapeAnalysis'
>
> > On Jan 3, 11:04 pm, Aaron Cohen  wrote:
>
> > > What JVM 6 sub-version are you using?
>
> > > Does it make any difference if you specify -XX:+DoEscapeAnalysis at
> > > the command line? Various JVM 6 sub-versions enable and disable it by
> > > default and it can make a pretty hefty difference if it isn't enabled.
>
> > > -- Aaron
>
> > > On Sun, Jan 3, 2010 at 4:00 PM, Gabi  wrote:
> > > > I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0).
> > > > Clojure's sort is is 4 to 5 times slower than sorted-vec2
> > > > Maybe somebody with a Vista machine double check this?
>
> > > > On Jan 3, 5:51 pm, ianp  wrote:
> > > >> > More findings: The reason that the Clojure's original sort is  8 
> > > >> > times slower
>
> > > >> I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with
> > > >> Apple’s Java 6 VM in case that has anything to do with it, but here's
> > > >> what I get (after running the tests several times to warm up hotspot):
>
> > > >> user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
>
> > > >> user=> (time (dotimes [_ 1000] (sort v)))
> > > >> "Elapsed time: 4376.471 msecs"
>
> > > >> user=> (defn sorted-vec [coll]
> > > >>          (let [a (into-array coll)]
> > > >>            (java.util.Arrays/sort a)
> > > >>            (vec a)))
> > > >> user=> (time (dotimes [_ 1000] (sorted-vec v)))
> > > >> "Elapsed time: 3254.371 msecs"
>
> > > >> user=> (defn sorted-vec-2 [coll]
> > > >>          (let [a (to-array coll)]
> > > >>            (java.util.Arrays/sort a)
> > > >>            (vec a)))
> > > >> user=> (time (dotimes [_ 1000] (sorted-vec-2 v)))
> > > >> "Elapsed time: 2599.63 msecs"
>
> > > >> So sorted-vec is faster, but not an order of magnitude, and sorted-
> > > >> vec-2 is faster again.
>
> > > >> Another alternative that may be worth considering is leaving the data
> > > >> in the array and using aget to access elements (this should give you O
> > > >> (1) access times vs. O(log32N) AFAIK). This may be a solution if
> > > >> you're not mutating the data in the array, but I'd be careful about
> > > >> this optimisation unless it really gets a large speed boost for your
> > > >> code.
>
> > > > --
> > > > 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 moderated - please be patient with 
> > > > your first post.
> > > > To unsubscribe from this group, send email to
> > > > clojure+unsubscr...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
It turns out I run the client version.
When running the server version (-server) the performance of sort is 4
times better.


On Jan 3, 11:20 pm, Gabi  wrote:
> "1.6.0_17" .It doesn't support this flag:
> Unrecognized VM option '+DoEscapeAnalysis'
>
> On Jan 3, 11:04 pm, Aaron Cohen  wrote:
>
> > What JVM 6 sub-version are you using?
>
> > Does it make any difference if you specify -XX:+DoEscapeAnalysis at
> > the command line? Various JVM 6 sub-versions enable and disable it by
> > default and it can make a pretty hefty difference if it isn't enabled.
>
> > -- Aaron
>
> > On Sun, Jan 3, 2010 at 4:00 PM, Gabi  wrote:
> > > I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0).
> > > Clojure's sort is is 4 to 5 times slower than sorted-vec2
> > > Maybe somebody with a Vista machine double check this?
>
> > > On Jan 3, 5:51 pm, ianp  wrote:
> > >> > More findings: The reason that the Clojure's original sort is  8 times 
> > >> > slower
>
> > >> I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with
> > >> Apple’s Java 6 VM in case that has anything to do with it, but here's
> > >> what I get (after running the tests several times to warm up hotspot):
>
> > >> user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
>
> > >> user=> (time (dotimes [_ 1000] (sort v)))
> > >> "Elapsed time: 4376.471 msecs"
>
> > >> user=> (defn sorted-vec [coll]
> > >>          (let [a (into-array coll)]
> > >>            (java.util.Arrays/sort a)
> > >>            (vec a)))
> > >> user=> (time (dotimes [_ 1000] (sorted-vec v)))
> > >> "Elapsed time: 3254.371 msecs"
>
> > >> user=> (defn sorted-vec-2 [coll]
> > >>          (let [a (to-array coll)]
> > >>            (java.util.Arrays/sort a)
> > >>            (vec a)))
> > >> user=> (time (dotimes [_ 1000] (sorted-vec-2 v)))
> > >> "Elapsed time: 2599.63 msecs"
>
> > >> So sorted-vec is faster, but not an order of magnitude, and sorted-
> > >> vec-2 is faster again.
>
> > >> Another alternative that may be worth considering is leaving the data
> > >> in the array and using aget to access elements (this should give you O
> > >> (1) access times vs. O(log32N) AFAIK). This may be a solution if
> > >> you're not mutating the data in the array, but I'd be careful about
> > >> this optimisation unless it really gets a large speed boost for your
> > >> code.
>
> > > --
> > > 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 moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
"1.6.0_17" .It doesn't support this flag:
Unrecognized VM option '+DoEscapeAnalysis'

On Jan 3, 11:04 pm, Aaron Cohen  wrote:
> What JVM 6 sub-version are you using?
>
> Does it make any difference if you specify -XX:+DoEscapeAnalysis at
> the command line? Various JVM 6 sub-versions enable and disable it by
> default and it can make a pretty hefty difference if it isn't enabled.
>
> -- Aaron
>
> On Sun, Jan 3, 2010 at 4:00 PM, Gabi  wrote:
> > I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0).
> > Clojure's sort is is 4 to 5 times slower than sorted-vec2
> > Maybe somebody with a Vista machine double check this?
>
> > On Jan 3, 5:51 pm, ianp  wrote:
> >> > More findings: The reason that the Clojure's original sort is  8 times 
> >> > slower
>
> >> I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with
> >> Apple’s Java 6 VM in case that has anything to do with it, but here's
> >> what I get (after running the tests several times to warm up hotspot):
>
> >> user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
>
> >> user=> (time (dotimes [_ 1000] (sort v)))
> >> "Elapsed time: 4376.471 msecs"
>
> >> user=> (defn sorted-vec [coll]
> >>          (let [a (into-array coll)]
> >>            (java.util.Arrays/sort a)
> >>            (vec a)))
> >> user=> (time (dotimes [_ 1000] (sorted-vec v)))
> >> "Elapsed time: 3254.371 msecs"
>
> >> user=> (defn sorted-vec-2 [coll]
> >>          (let [a (to-array coll)]
> >>            (java.util.Arrays/sort a)
> >>            (vec a)))
> >> user=> (time (dotimes [_ 1000] (sorted-vec-2 v)))
> >> "Elapsed time: 2599.63 msecs"
>
> >> So sorted-vec is faster, but not an order of magnitude, and sorted-
> >> vec-2 is faster again.
>
> >> Another alternative that may be worth considering is leaving the data
> >> in the array and using aget to access elements (this should give you O
> >> (1) access times vs. O(log32N) AFAIK). This may be a solution if
> >> you're not mutating the data in the array, but I'd be careful about
> >> this optimisation unless it really gets a large speed boost for your
> >> code.
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0).
Clojure's sort is is 4 to 5 times slower than sorted-vec2
Maybe somebody with a Vista machine double check this?


On Jan 3, 5:51 pm, ianp  wrote:
> > More findings: The reason that the Clojure's original sort is  8 times 
> > slower
>
> I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with
> Apple’s Java 6 VM in case that has anything to do with it, but here's
> what I get (after running the tests several times to warm up hotspot):
>
> user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
>
> user=> (time (dotimes [_ 1000] (sort v)))
> "Elapsed time: 4376.471 msecs"
>
> user=> (defn sorted-vec [coll]
>          (let [a (into-array coll)]
>            (java.util.Arrays/sort a)
>            (vec a)))
> user=> (time (dotimes [_ 1000] (sorted-vec v)))
> "Elapsed time: 3254.371 msecs"
>
> user=> (defn sorted-vec-2 [coll]
>          (let [a (to-array coll)]
>            (java.util.Arrays/sort a)
>            (vec a)))
> user=> (time (dotimes [_ 1000] (sorted-vec-2 v)))
> "Elapsed time: 2599.63 msecs"
>
> So sorted-vec is faster, but not an order of magnitude, and sorted-
> vec-2 is faster again.
>
> Another alternative that may be worth considering is leaving the data
> in the array and using aget to access elements (this should give you O
> (1) access times vs. O(log32N) AFAIK). This may be a solution if
> you're not mutating the data in the array, but I'd be careful about
> this optimisation unless it really gets a large speed boost for your
> code.

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
More findings: The reason that the Clojure's original sort is  8 times
slower than sorted-vec2 is only because  Clojure uses its own
comparator by default, instead of using Java's default comparator.
Otherwise it's same performance.

;Modified clojure.core.clj sort
(defn sort2
  "Returns a sorted sequence of the items in coll. If no comparator is
  supplied, uses compare. comparator must
  implement java.util.Comparator."
  ([coll]
   (if (seq coll)
 (let [a (to-array coll)]
   (java.util.Arrays/sort a)
   (seq a))
 ()))
  ([#^java.util.Comparator comp coll]
   (if (seq coll)
 (let [a (to-array coll)]
   (. java.util.Arrays (sort a comp))
   (seq a))
 (

;Modified sort
user=> (time (dotimes[_ 1000](sort2 v)))
"Elapsed time: 3510.047755 msecs"

;Original sort
user=> (time (dotimes[_ 1000](sort v)))
"Elapsed time: 23872.07338 msecs"

;Sorted vec. Returns vector, not sequence
user=> (time (dotimes[_ 1000](sorted-vec2 v)))
"Elapsed time: 3534.578648 msecs"

On Jan 3, 1:54 pm, Gabi  wrote:
> I investigated a little bit more. Seems that (into-array) is slows
> things down because it seqs (un-necessarily?) that vector before
> passing to clojure.lang.RT/seqToTypedArray.
>
> I almost doubled the speed of sorted-vec by using clojure.lang.RT/
> toArray:
>
> (defn sorted-vec2
>   [coll]
>   (let [arr (clojure.lang.RT/toArray coll)]
>     (java.util.Arrays/sort arr)
>     (vec arr)))
>
> user=>  (time(dotimes [_ 1000] (sorted-vec2 v)))
> "Elapsed time: 3502.369933 msecs"
>
> user=>  (time(dotimes [_ 1000] (sorted-vec v)))
> "Elapsed time: 5874.088425 msecs"
>
> On Jan 3, 10:29 am, Gabi  wrote:
>
> > The sorted-vec is ~4 times faster than Clojure's sort (on my humble
> > old machine):
>
> > user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
> > #'user/v
> > user=> (time(dotimes [_ 1000] (sort v)))
> > "Elapsed time: 23945.682336 msecs"
> > nil
> > user=> (time(dotimes [_ 1000] (sorted-vec v)))
> > "Elapsed time: 6030.585433 msecs"
>
> > BTW we have state here (the native Java array). Is it thread safe ?
>
> > On Jan 2, 11:04 pm, Meikel Brandmeyer  wrote:
>
> > > Hi,
>
> > > Am 02.01.2010 um 20:17 schrieb ianp:
>
> > > >> A bit uglier, but ought to be quite fast.
>
> > > > Doesn't need to be that ugly, this looks OK to me at least:
>
> > > > (defn sorted-vec [coll]
> > > >  (doto (into-array coll)
> > > >    (java.util.Arrays/sort)
> > > >    (vec)))
>
> > > > It'd also be possible to generalise the return type by passing in a fn
> > > > to apply to the sorted array.
>
> > > Unfortunately the above code does not work, because it returns the array 
> > > and not the vector.
>
> > > (defn sorted-vec
> > >   [coll]
> > >   (let [arr (into-array coll)]
> > >     (java.util.Array/sort arr)
> > >     (vec arr)))
>
> > > How fast is vec on an array? Isn't there a LazilyPersistentVector which 
> > > just wraps the array?
>
> > > Sincerely
> > > Meikel

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
I investigated a little bit more. Seems that (into-array) is slows
things down because it seqs (un-necessarily?) that vector before
passing to clojure.lang.RT/seqToTypedArray.

I almost doubled the speed of sorted-vec by using clojure.lang.RT/
toArray:

(defn sorted-vec2
  [coll]
  (let [arr (clojure.lang.RT/toArray coll)]
(java.util.Arrays/sort arr)
(vec arr)))

user=>  (time(dotimes [_ 1000] (sorted-vec2 v)))
"Elapsed time: 3502.369933 msecs"

user=>  (time(dotimes [_ 1000] (sorted-vec v)))
"Elapsed time: 5874.088425 msecs"



On Jan 3, 10:29 am, Gabi  wrote:
> The sorted-vec is ~4 times faster than Clojure's sort (on my humble
> old machine):
>
> user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
> #'user/v
> user=> (time(dotimes [_ 1000] (sort v)))
> "Elapsed time: 23945.682336 msecs"
> nil
> user=> (time(dotimes [_ 1000] (sorted-vec v)))
> "Elapsed time: 6030.585433 msecs"
>
> BTW we have state here (the native Java array). Is it thread safe ?
>
> On Jan 2, 11:04 pm, Meikel Brandmeyer  wrote:
>
>
>
>
>
> > Hi,
>
> > Am 02.01.2010 um 20:17 schrieb ianp:
>
> > >> A bit uglier, but ought to be quite fast.
>
> > > Doesn't need to be that ugly, this looks OK to me at least:
>
> > > (defn sorted-vec [coll]
> > >  (doto (into-array coll)
> > >    (java.util.Arrays/sort)
> > >    (vec)))
>
> > > It'd also be possible to generalise the return type by passing in a fn
> > > to apply to the sorted array.
>
> > Unfortunately the above code does not work, because it returns the array 
> > and not the vector.
>
> > (defn sorted-vec
> >   [coll]
> >   (let [arr (into-array coll)]
> >     (java.util.Array/sort arr)
> >     (vec arr)))
>
> > How fast is vec on an array? Isn't there a LazilyPersistentVector which 
> > just wraps the array?
>
> > Sincerely
> > Meikel

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Sequence to Vector

2010-01-03 Thread Gabi
The sorted-vec is ~4 times faster than Clojure's sort (on my humble
old machine):

user=> (def v (vec (take 1 (repeatedly #(rand-int 10)
#'user/v
user=> (time(dotimes [_ 1000] (sort v)))
"Elapsed time: 23945.682336 msecs"
nil
user=> (time(dotimes [_ 1000] (sorted-vec v)))
"Elapsed time: 6030.585433 msecs"

BTW we have state here (the native Java array). Is it thread safe ?

On Jan 2, 11:04 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 02.01.2010 um 20:17 schrieb ianp:
>
> >> A bit uglier, but ought to be quite fast.
>
> > Doesn't need to be that ugly, this looks OK to me at least:
>
> > (defn sorted-vec [coll]
> >  (doto (into-array coll)
> >    (java.util.Arrays/sort)
> >    (vec)))
>
> > It'd also be possible to generalise the return type by passing in a fn
> > to apply to the sorted array.
>
> Unfortunately the above code does not work, because it returns the array and 
> not the vector.
>
> (defn sorted-vec
>   [coll]
>   (let [arr (into-array coll)]
>     (java.util.Array/sort arr)
>     (vec arr)))
>
> How fast is vec on an array? Isn't there a LazilyPersistentVector which just 
> wraps the array?
>
> Sincerely
> Meikel

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Sequence to Vector

2010-01-01 Thread Gabi
What is the preferred way getting a vector back from sequence, after a
sequence producing operation (like sort)? Does using (vec..) on a
sequence that was a vector is costly?

One (bad?) possibility is creating a new vector out of sequence:

(vec (sort [1 2 3 4 5 6]))

I am asking because I need random access (nth ..) to huge sorted
vectors - which are now actually huge sequences after the sort, with
horrible O(n) random access time

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-01 Thread Gabi
I am interested in the idea: Completely stateless set of Clojure nodes
(on many machines), operating on a central state stored in some
datastore.
If transactions could be managed somehow, I think it would be very
compelling model for many applications.

On Jan 1, 11:07 pm, Julian Morrison  wrote:
> I've just recently been poking around these NoSQLs investigating their
> features, so...
>
> Redis has limited data structures - flat un-nested lists and sets, and
> plain strings. It doesn't have sets exactly - just keys and values.
> Nothing nested at all, unless you serialize to strings. No indexes,
> although you can hack up your own.
>
> To be honest, Redis isn't that impressive versus what's in Clojure
> already. It's an in-memory DB (so it's not much different from ref
> +dosync) and it intermittently spits a snapshot to disk. If you can
> live with an in-process DB, you could copy (and exceed) its features
> including snapshot saving in a page of pure Clojure code, and beat it
> on speed too.
>
> Contrast MongoDB: slower because it bothers to save things, but still
> around twice as fast as MySQL and much faster than CouchDB (cite: the
> benchmarks page). Arbitrarily nested collections, indexes, atomic
> updates (in place operations like inc and append, or atomic compare-
> and-set), JSON syntax, typed data, replication (built in) and sharding
> (via a broker process).
>
> (MongoDB downsides: it grows files in a very greedy way to try and
> minimize data fragmentation, and it needs a 64bit machine to store
> more than about 2Gb.)
>
> On Dec 30 2009, 11:52 am, Gabi  wrote:
>
> > On first look, Redis and Clojure seems to be a perfect match. They
> > both handle sets and maps efficiently. If one could find an easy way
> > to store and retrieve Clojure data structures to Redis (even a small
> > subset- just a list or a set), a distributed clojure app could be very
> > easy (and effective?) thing to do - The stateless Clojure nodes would
> > share and operate on the same central data structure which is stored
> > in Redis). What do you thing ? Is it worth investigating further?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2010-01-01 Thread Gabi
Jackrabbit is heavy. It might be powerful but I am sure it is much
slower than Redis or MongoDB.

On Dec 31 2009, 6:59 pm, jem  wrote:
> Something else to look at might be the Apache Jackrabbit project 
> athttp://jackrabbit.apache.org/.
>
> I've been looking at tools along these lines as well, and recently
> looked at Redis for the same reasons.  Right now, though, I'm focusing
> my attention on Jackrabbit which is an implementation of the JSR170
> repository specifications.  It supports hierarchical data and lists.
> I was looking for some way to save dynamic objects (basically runtime
> defined maps) and this looks like it might work.
>
> JSR170  defines a repository as:
>
> "A content repository consists of one or more workspaces, each of
> which contains a tree of items. An item is either a node or a
> property. Each node may have zero or more child nodes and zero or more
> child properties. There is a single root node per workspace, which has
> no parent. All other nodes have one parent. Properties have one parent
> (a node) and cannot have children; they are the leaves of the tree.
> All of the actual content in the repository is stored within the
> values of the properties."
>
> The available property types cover what appear to be all the bases,
> including references to other nodes to prevent cycles when
> serializing. It can support annotated Java objects or use the Node
> building capability directly and allows querying similar to XPath.
> Since it is a Java project, using it from Clojure should be trivial to
> use.
>
> On Dec 31, 5:29 am, Steve Purcell  wrote:
>
> > Not sure if it's any help, but here's a variant of memoize I wrote, which 
> > stores arbitrary readable/printable objects to redis:
>
> >http://gist.github.com/266689
>
> > (If there's any interest, I'll wrap it up in a github project and push it 
> > to clojars.)
>
> > Redis isn't a hierarchical store, so its array/set operations would only 
> > benefit the most shallow of data structures.
>
> > -Steve
>
> > On 30 Dec 2009, at 11:52, Gabi wrote:
>
> > > On first look, Redis and Clojure seems to be a perfect match. They
> > > both handle sets and maps efficiently. If one could find an easy way
> > > to store and retrieve Clojure data structures to Redis (even a small
> > > subset- just a list or a set), a distributed clojure app could be very
> > > easy (and effective?) thing to do - The stateless Clojure nodes would
> > > share and operate on the same central data structure which is stored
> > > in Redis). What do you thing ? Is it worth investigating further?
>
> > > --
> > > 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 moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure + Redis

2009-12-31 Thread Gabi
Yes. I think it is of much interest. What if I stored a shared data
structure in redis (only because its the fastest), using your memoize
variant, and process (maybe even updated it) it in parallel from
different Clojure nodes. Some kind of primitive map/reduce mechanism I
think.

On Dec 31, 12:29 pm, Steve Purcell  wrote:
> Not sure if it's any help, but here's a variant of memoize I wrote, which 
> stores arbitrary readable/printable objects to redis:
>
> http://gist.github.com/266689
>
> (If there's any interest, I'll wrap it up in a github project and push it to 
> clojars.)
>
> Redis isn't a hierarchical store, so its array/set operations would only 
> benefit the most shallow of data structures.
>
> -Steve
>
> On 30 Dec 2009, at 11:52, Gabi wrote:
>
> > On first look, Redis and Clojure seems to be a perfect match. They
> > both handle sets and maps efficiently. If one could find an easy way
> > to store and retrieve Clojure data structures to Redis (even a small
> > subset- just a list or a set), a distributed clojure app could be very
> > easy (and effective?) thing to do - The stateless Clojure nodes would
> > share and operate on the same central data structure which is stored
> > in Redis). What do you thing ? Is it worth investigating further?
>
> > --
> > 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 moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Clojure + Redis

2009-12-30 Thread Gabi
On first look, Redis and Clojure seems to be a perfect match. They
both handle sets and maps efficiently. If one could find an easy way
to store and retrieve Clojure data structures to Redis (even a small
subset- just a list or a set), a distributed clojure app could be very
easy (and effective?) thing to do - The stateless Clojure nodes would
share and operate on the same central data structure which is stored
in Redis). What do you thing ? Is it worth investigating further?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Recommendation for Clojure Indentation tool

2009-12-22 Thread Gabi
I need a simple command-line tool to indent Clojure source files.
Any recommendation ?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: eval performance

2009-12-22 Thread Gabi
Superb!
This is exactly what I needed.. A way to get rid of the awkward intern
and boost performance.
Have you progressed far with your GP experimenting ?






On Dec 22, 4:17 am, kyle smith  wrote:
> Here's the macro I used when I dabbled in Genetic Programming:
>
> user> (time (dotimes [_ 1000]
>               (intern  'user 'x (rand))
>               (eval '(+ (* x x) 5
> "Elapsed time: 425.754877 msecs"
>
> user> (defmacro capture-vars [vars expr]
>         `(fn [...@vars] ~(first (next expr
> #'user/capture-vars
> user> (time (let [f (eval (capture-vars [x] '(+ (* x x) 5)))]
>               (dotimes [_ 100];note the iterations!
>                 (f (rand)
> "Elapsed time: 73.936157 msecs"

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: eval performance

2009-12-21 Thread Gabi
The problem with is that I need to execute the same function with
different bindings each time. So caching won't help me
For example I need to do something like:

(dotimes [_ 1000]
  (intern  'user 'x (rand))
  (eval '(prn (+(* x x) 5

On Dec 21, 11:53 pm, AlexK  wrote:
> What eval does, is wrapping (fn* [] ) around its
> arguments, compiling that, and calling the resulting function object
> (except if your list starts with a 'do or a 'def).
>
> While Clojure's compiler is pretty fast, you should try not to use
> eval. If you want to pass code around you should try something like
> storing functions in a map or something similar.
>
> If you think that you have to eval lists, try wrapping them in (fn
> [] ...) and eval that form instead. You'll get a function object which
> was compiled once, but can be called as many times as you want.
>
> eg.
>
> (defn form->fn [list-to-eval]
>   (eval (list 'fn [] list-to-eval))) ;this returns a fn
>
> (def form->fn (memoize form->fn)) ;caches the resulting fns, beware of
> memory leaks though
>
> ((form->fn '(println "Hello World")))
> ((form->fn '(println "Hello World")))
> ((form->fn '(println "Hello World"))) ; should compile only once
>
> Alex

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: eval performance

2009-12-21 Thread Gabi
Experimenting with GeneticProgramming with Clojure..

On Dec 21, 11:23 pm, rob  wrote:
> Sorry, I somehow accidentally sent it before I was done typing.  The
> rest of my sentence was "what are you trying to do thar requires the
> use of evals in that way".
>
> On Dec 21, 4:22 pm, rob  wrote:
>
> > It sounds like your use of evals might be something that could be done
> > better using a more idiomatic clojure approach.  What are you trying
> > to do that re
>
> > On Dec 21, 2:32 pm, Gabi  wrote:
>
> > > Hi
> > > I have this program that needs to do many eval's to same expression
> > > (eval '(some-list-to-execut..))
> > > My question is how can this be  optimized  ? Does eval compile the
> > > evaled expression ? Does it re-compile the evaluated expression again
> > > and again? Maybe I could compile the evaled expression once and
> > > somehow eval the compiled bytcode?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


eval performance

2009-12-21 Thread Gabi
Hi
I have this program that needs to do many eval's to same expression
(eval '(some-list-to-execut..))
My question is how can this be  optimized  ? Does eval compile the
evaled expression ? Does it re-compile the evaluated expression again
and again? Maybe I could compile the evaled expression once and
somehow eval the compiled bytcode?

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Recursions under lazy-seq - how does it work?

2009-11-25 Thread Gabi
Ok. Now I get it. Cool stuff

On Nov 25, 4:18 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On Nov 25, 9:10 am, Gabi  wrote:
>
> > For example why doesn't the following "repeatedly" never crash?
>
> > (defn repeatedly
> >   [f] (lazy-seq (cons (f) (repeatedly f
>
> Because the nested call is deferred until the sequence is realised.
> Then the original function already returned. So it does not build up
> the stack until it crashes.
>
> > (last (repeatedly rand)) ;won't crash
>
> But it won't return either. Not sure which result is more
> favorable. ;)
>
> Sincerely
> Meikel

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Recursions under lazy-seq - how does it work?

2009-11-25 Thread Gabi
Very interesting indeed. I am not sure I understand completely, but by
intuition I presume that the recursive call actually creates a new
heap allocated LazySeq (with the function definition inside) . So is
there some help from the compiler for this? How does the recursive
call suddenly transfers into a call to a LazySeq object ?

On Nov 25, 6:29 pm, David Brown  wrote:
> On Wed, Nov 25, 2009 at 12:10:36AM -0800, Gabi wrote:
> >How come that infinite recursions under lazy-seq won't crash the
> >program, whilst regular infinite recursion would crash the program ?
> >What's the trick ?
>
> >For example why doesn't the following "repeatedly" never crash?
>
> >(defn repeatedly
> >  [f] (lazy-seq (cons (f) (repeatedly f
>
> >(last (repeatedly rand)) ;won't crash
>
> The JVM doesn't support tail call elimination, so an infinite
> retursion causes a new stack frame for each call.  The stack is fairly
> small and will quickly be exhausted.
>
> The lazy-seq, instead, wraps the contents up into a function closure
> and wraps it in a clojure.lang.LazySeq.  This causes a few heap
> allocations.  If you were to keep the head of this chain, you would
> also exhaust the heap (which would take a while longer).  But since
> your example is only walking along next, each item generated contains
> no more references, and can be garbage collected.
>
> Lazy-seq basically turns a stack allocation into a heap allocation.
> This both allows for not allow of the sequence to be allocated, but
> allows the earlier parts of the sequence to be collected.
>
> Try:
>
>   (let [r (repeatedly rand)]
>     (last r)
>     r)
>
> which will try to keep the whole sequence in memory, and eventually
> exhaust your heap.
>
> David

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Recursions under lazy-seq - how does it work?

2009-11-25 Thread Gabi
Just out of curiosity,
How come that infinite recursions under lazy-seq won't crash the
program, whilst regular infinite recursion would crash the program ?
What's the trick ?

For example why doesn't the following "repeatedly" never crash?

(defn repeatedly
  [f] (lazy-seq (cons (f) (repeatedly f

(last (repeatedly rand)) ;won't crash

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Suggestion: Add should_cache? flag to lazy-seq

2009-11-20 Thread Gabi
This would solve the "holding to the head" problem.
Many times, lazy-seq would be used without the need to get the same
cell twice.
In this case, avoiding cashing would both enhance performance and more
importantly would avoid OutOfMemoryError Exceptions like in:

(def r (repeatedly #(rand)))
(last r)

So, something like:
(defn lazy-seq [should_cache? &body] ..
would be beneficial (I think :)

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en