finding a key which does not exist in the map

2011-05-26 Thread Sunil S Nandihalli
Hello everybody, I was wondering if there is a way to find a key which does not exist in a map in an efficient way. you can assume that all the keys are integers. I currently do something like (defn non-existent-key [mp] (first (filter (comp not mp) (range Is there a possibly m

Re: finding a key which does not exist in the map

2011-05-26 Thread Andreas Kostler
If you have control over the creation of the map, you could use something like a global counter to provide the next valid key. You could also use a sorted map and just increment to last (biggest) key in the map. Or you could use a random number. If the range is big enough, the probability of col

Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
This is what I've come up with so far...it should give a bit of an idea of what I'm using it for: (defprotocol PSparseVec (norm [this]) (cnt [this]) (ith-val [this i]) (unit-vec [this]) (assc [this i o])) (defrecord SparseVec [indices vals] PSparseVec (cnt [this] (count indices))

Re: ANN: SoyMacchiato - JDK7 for OS X

2011-05-26 Thread rogerdpack
> I've been doing some experimentation with Clojure on various setups of > Java/JDK 1.7, including the DaVinci Machine enhancements. Do you find it reasonably stable on OS X? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send

Re: Efficient sparse vector representation...

2011-05-26 Thread Ken Wesson
On Thu, May 26, 2011 at 8:19 AM, Andreas Kostler wrote: >          (let [new-indices (sort (conj indices i)) >                new-idx (bin-search new-indices i) >                [chunk1 chunk2] (split-at new-idx vals)] >            (SparseVec. new-indices (into (conj (vec chunk1) o) chunk2)) >

Re: Efficient sparse vector representation...

2011-05-26 Thread Steve Miner
I've used this approach before. It was simple and worked well. Note that assoc can take multiple keys and vals so you can simplify it to (assoc m k v v k) instead of nesting the assoc calls. If there's any chance of a collision, you could be defensive and test for (contains? m k) or (contains?

Architecture for a Clojure project

2011-05-26 Thread Max Weber
Hi, imaging you could do a software project from scratch and Clojure is the main programming language. What architecture would you choose? Of course it depends, so here are some requirements and basic conditions: - Let's assume that we are building a web application for some social media st

Re: San Francisco Clojure Users

2011-05-26 Thread Emeka
David, Yes. I am in Nigeria. Emeka On Tue, May 24, 2011 at 9:43 AM, David Jagoe wrote: > Are you in Nigeria? > > Anyone else on this list in Africa? > > > > On Sunday, 22 May 2011, Emeka wrote: > > Okay. > > I live in Africa... maybe we should have online meetups for now. > > Emeka > > > > On

Re: How to convert a string to a data structure

2011-05-26 Thread ron peterson
Thank you everyone for the solution. Ron. On May 25, 6:24 pm, Luc Prefontaine wrote: > Use: > > (read-string (read-string "[{:a \"blah\" :b 23} {:d 34 :c \"hello\"}]") > > I believe your expression is wrong, (:d should be {:d. > > Luc P. > > On Wed, 25 May 2011 18:04:11 -0700 (PDT) > > ron peter

Re: finding a key which does not exist in the map

2011-05-26 Thread Walter van der Laan
You could use this: (defn non-existing-key [mp] (inc (reduce max (keys mp For example: (non-existing-key {1 "a" 2 "b"}) => 3 -- 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 p

Re: Debian packages

2011-05-26 Thread Phil Hagelberg
On May 25, 7:39 pm, Rob Lachlan wrote: > I'm curious about this as well, because of the ICFP programming > contest. The contest organizers are soliciting requests for Debian packages to > be installed on the contest environment.  I don't suppose that this is > the reason that you're asking? No, I

Recur and primitives?!?

2011-05-26 Thread Andreas Kostler
Hi guys, I'm kinda lost as to what's going on here...With clojure-1.2.0 (defn bin-search [v k c] (loop [l 0 h (dec (count v))] (if (> l h) false (let [m (quot (+ l h) 2) m-v (v m)] (cond (> m-v k) (recur (inc m) h) (> k m-v) (recur l

Re: Recur and primitives?!?

2011-05-26 Thread Luc Prefontaine
h gets boxed somehow from integer to something else when the recur is executed. No idea where however. Look at this, it may help: http://groups.google.com/group/clojure/browse_thread/thread/e4574bbb01155c4d On Fri, 27 May 2011 09:54:19 +1000 Andreas Kostler wrote: > Hi guys, > I'm kinda lost

Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
Thanks Ken, using this approach brings a ~1000 times speedup :) (def a (sparse-vec (range 10) (range 10))) (def b (time (assc-ken a 11 0))) "Elapsed time: 0.249 msecs" (def b (time (assc a 11 0))) "Elapsed time: 252.06 msecs" Very worthwhile and it's clearer as well. Cheers Andr

Re: Efficient sparse vector representation...

2011-05-26 Thread Ken Wesson
On Thu, May 26, 2011 at 8:50 PM, Andreas Kostler wrote: > Thanks Ken, > using this approach brings a ~1000 times speedup :) > > (def a (sparse-vec (range 10) (range 10))) > > (def b (time (assc-ken a 11 0))) > "Elapsed time: 0.249 msecs" > > (def b (time (assc a 11 0))) > "Elapsed

Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
That explains the good performance. Either way, the implementation is quite a bit clearer. I've also compared some operations of sparse-vec vs. plain map. The inner product is slightly faster for vecs with < 10 elements, then map takes over. norm and unit-vector operations are quite in favo

Re: Recur and primitives?!?

2011-05-26 Thread Armando Blancas
Coercing m to int somehow prevents h from being boxed: user=> (defn bin-search [v k c] (loop [l 0 h (dec (count v))] (if (> l h) false (let [m (int (quot (+ l h) 2)) m-v (v m)] (cond (> m-v k) (recur (inc m) h) (> k m-v) (recur l (dec

Re: Debian packages

2011-05-26 Thread Daigo Moriwaki
I also long for the latest Clojure in Debian. The current main packager seems to be too busy to responsive. With discussion at debian-java mail list, I have just uploaded Clojure 1.2.0. Since it is a brand new source version, it will take several days for FTP Masters to accept it. If you have com

Re: Recur and primitives?!?

2011-05-26 Thread Ken Wesson
On Thu, May 26, 2011 at 10:28 PM, Armando Blancas wrote: > Coercing m to int somehow prevents h from being boxed: > > user=> (defn bin-search [v k c] >  (loop [l 0 >         h (dec (count v))] >    (if (> l h) false >        (let [m (int (quot (+ l h) 2)) >              m-v (v m)] >          (cond

Re: Recur and primitives?!?

2011-05-26 Thread Andreas Kostler
The question is though, why doesn't this work to begin with and why does it work on 1.3.0-master-SNAPSHOT...? Is it broken or am I doing something wrong? :) Andreas On 27/05/2011, at 1:28 PM, Ken Wesson wrote: > On Thu, May 26, 2011 at 10:28 PM, Armando Blancas > wrote: >> Coercing m to int so

Re: Radically simplified Emacs and SLIME setup

2011-05-26 Thread J.R. Garcia
I compiled a new version of emacs from source and started it up. clojure-jack-in just worked flawlessly. This is stupid simple! Thanks for your hard work! It's much appreciated for emacs newcomers like me (I'm a vim user)! Thanks again, J.R. Garcia On May 24, 6:55 pm, Phil Hagelberg wrote: > On

Re: Recur and primitives?!?

2011-05-26 Thread Ken Wesson
On Thu, May 26, 2011 at 11:31 PM, Andreas Kostler wrote: > The question is though, why doesn't this work to begin with and why does it > work on 1.3.0-master-SNAPSHOT...? > Is it broken or am I doing something wrong? :) On further investigation, it looks like Clojure considers the type of (count

Re: Recur and primitives?!?

2011-05-26 Thread Luc Prefontaine
Nope it's not broken, in 1.3 numeric computations changed. Rich wanted to streamline the behavior and gain performance in numeric computations. Non floating point values are now all longs except if you cast them explicitly (java interop needs this), floats are now all doubles (the widest type of

Re: finding a key which does not exist in the map

2011-05-26 Thread Sunil S Nandihalli
I don't think yours is going to be anymore efficient than the one I had initially posted .. In fact it might be slower in majority of the cases.. Thanks, Sunil. On Fri, May 27, 2011 at 12:57 AM, Walter van der Laan < waltervanderl...@gmail.com> wrote: > You could use this: > (defn non-existing-ke