finding paths in clojure with Floyd-Warshall - ugly code

2009-09-14 Thread ajuc
Hello, I'm new in clojure and lisp, and I have problem with making this code elegant (or at least short). This is Floyd-Warshall algorithm - very simple algorithm in imperative form (3 nested for loops). In clojure the best I've get so far is this monstrosity: (defn create-graph [nodes distance

Re: finding paths in clojure with Floyd-Warshall - ugly code

2009-09-15 Thread ajuc
> [snip] > > You are "accumulating" a result, which hints us at 'reduce. > And 'for provides the nested enumeration: > > (defn floyd-warshall2 [{:keys [nodes distances]}] >   (reduce (fn [[distances prevs] [k x y]] >             (let [d (+ (distances [x k] Double/POSITIVE_INFINITY) >              

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread ajuc
I'm beginner myself, but I' think it's because it creates 100 new classes (for each new anonymous fn). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@g

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread ajuc
I was probably wrong - too many classes should throw error about permGenSpace (at least in java they do). Also for me it works for n=100, fails for 1000 (clojurebox 1.0). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Goog

local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-13 Thread ajuc
Hello. I've tried to translate nice Hilbert-curve-index calculating function to clojure (http://blog.notdot.net/2009/11/Damn-Cool-Algorithms- Spatial-indexing-with-Quadtrees-and-Hilbert-Curves). I've got sth like that: (def hilbert-map { :a {[0 0] [0 :d], [0 1] [1 :a], [1 0] [3 :b], [1 1] [2 :

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-14 Thread ajuc
> > I would like to somehow hide the global hilbert-map into my function, > > but I can't see how to do that. > > Just put the literal directly into the function. > > > Is this possible? I know that I can just inert literal into my let, > > but that degrades performance, when function is called man

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-14 Thread ajuc
> Eeeuw. > > Was this with a Clojure literal in the let, or with a non-trivial > calculation using constants? The only difference is literal map of maps in let form. Full code here: http://clojure.pastebin.com/m17b8d69 I have to install java one more time, when I try to start java - server, I ge

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-15 Thread ajuc
On 15 Lis, 00:21, John Harrop wrote: > On Sat, Nov 14, 2009 at 3:03 PM, ajuc wrote: > > I have to install java one more time, when I try to start java - > > server, I get: > > Error: no `server' JVM at `F:\Program Files\Java\jre6\bin\server > > \jvm.dll

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-15 Thread ajuc
> That's very odd. > > Rich needs to take a look at this. Letting a constant shouldn't have a > performance hit, IMO. > > Could you test whether it's faster to use your complex data structure > directly in the function, anonymously at the point of use, or to yank it > from a global var? Code (can

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-15 Thread ajuc
On 16 Lis, 01:32, Alex Osborne wrote: > Clojure's name gives a hint as to how do this: use a closure. :-)  Just > pull the let outside the defn: > > (let [hilbert-map {...}] >    (defn point-to-hilbert [...] >      ...)) Now it seems so obvious :). I guess I don't think functional yet. Thank yo

Re: positions

2009-11-19 Thread ajuc
On 20 Lis, 01:49, nchubrich wrote: > While we're on the topic, where is something like (subtract [1 2 3 3 4 > 4 5 6] evens) -> (1 3 3 5)? Doesn't seem to be in seq-utils or API. > Seems like there should be a parallel "multiset" library for colls, to > clojure.set. (I guess there could be two ve

Re: leiningen - a Clojure build tool

2009-11-22 Thread ajuc
On 22 Lis, 13:09, bOR_ wrote: > Ontopic: I might be missing something, but is there an obvious way to > do something like "lein src/chlamydia.clj" when I'm in the projects' > directory ("chlamydia"), to run a script as in "java -server > clojure.main chlamydia.clj"? I didn't see anything in the

Re: Specified behavior of every?

2009-12-03 Thread ajuc
(p(x) is true for all x in set X) is equivalent to (there are no such x in set X that p(x) is not true) So IMHO it's good that (every? pred []) returns true. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure

Re: Help with my vec matching function

2009-12-28 Thread ajuc
I would write this like that: (def v #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} ) (defn better-match [pattern match1 match2] ;;here choosing better matching vec from these 2 - sorry, I'm too lazy :) ) (reduce #(better-match [1 2 3] %1 %2) [] v) -- You received this messa

Re: Help with my vec matching function

2009-12-28 Thread ajuc
I don't know if I understan correctly the requirements, but this is my try. (def v #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} ) (defn matching [p v] (reduce + (map #(if (= %1 %2) 1 0) p v))) (defn better-match [p v1 v2] (if (or (> (matching p v1) (matching p v2))

Re: Help with my vec matching function

2009-12-28 Thread ajuc
On 28 Gru, 20:57, Robert Campbell wrote: > How might I add a third and final condition, where those candidates > with equal scores AND equal counts are all returned together? Reduce can work with functions like f : x * y -> x So we can modify function closest to be like that (untested): (clos

Re: Proposal: New fn assoc-in-with

2010-02-04 Thread ajuc
Maybe sth like that (defn assoc-in-maybe-creating [coll keys creator-fns value] ...) so it can be used: (assoc-in-maybe-creating [ {:a (sorted-map :X 1, :Y 2, :Z 3) :c (sorted-map :X 1, :Z 3)} {:b (sorted-map :X 1, :Y 2, :Z 3)} {:f (sorted-map :X 1, :Y 2)}] [0 :b :X] [vector

Re: How can we replace an element in a deeply nested list?

2010-05-14 Thread ajuc
Setq isn't functional - equivalent in clojure would be def, but it isn't meant to be used in that way. For your purpose there is better fit: postwalk-replace http://richhickey.github.com/clojure/clojure.walk-api.html#clojure.walk/postwalk-replace Greetings. -- You received this message because

Re: Enhanced Primitive Support

2010-06-18 Thread ajuc
+1 to safe-by-default. I use clojure for games, but if it will be possible to easily make computations fast, safe-by-default is more important. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.

Re: Could Clojure be used to program on top of GPU's?

2010-07-19 Thread ajuc
Look at Penumbra: http://github.com/ztellman/penumbra Greetings. -- 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 you

Re: Memoizing a recursive function?

2010-07-23 Thread ajuc
On 23 Lip, 01:51, Paul Mooser wrote: > Why not simply do: > > (defn fib [n] >   (println "called with " n) >   (if (> n 2) >     (+ (fib (- n 2)) (fib (- n 1))) >     1)) > > (def fib (memoize fib)) > > I inserted the println to verify when we were actually calling the > function, and I believe t

Re: Some Problem with Recursion

2010-09-09 Thread ajuc
On 9 Wrz, 14:30, Stefan Rohlfing wrote: > In order to get some more insight into recursion I wrote the following > function but ended up in confusion: > > (defn prefix->postfix [expr] >   (if (coll? expr) >     (let [ [op arg1 arg2] expr] >       [ (prefix->postfix arg1) (prefix->postfix arg2) o

Re: Some Problem with Recursion

2010-09-09 Thread ajuc
On 9 Wrz, 15:27, Stefan Rohlfing wrote: > The indentation was correct by got messed up when I copying the code. > > This is how I interpret the function: > 'expr' is only returned if (coll? expr) returns 'false', with is not > the case with an argument such as '(+ 2 4). > Next, this expression i

Re: A difficult Metaphor for Macros (especially for Java people)

2010-09-09 Thread ajuc
On 9 Wrz, 14:25, Andrew Gwozdziewycz wrote: > The fact that Lisp macros actually operate on the AST means that Lisp > macros can make *changes* to the AST (insert things, remove things, > rearrange things), and *not* just substitute FOO for BAR. This is a > hell of a lot more powerful. > > --htt

Re: can I force the JIT to be called immediately for certain pieces of code after it starts executing with out waiting for the JVM realize it is necessary....

2011-01-02 Thread ajuc
On 2 Sty, 12:01, Konrad Hinsen wrote: > On 2 Jan 2011, at 03:29, Sunil S Nandihalli wrote: > > >  can I force the JIT to be called immediately for certain pieces of   > > code after it starts executing with out waiting for the JVM realize   > > it is necessary? I would not mind jitting the who