Re: bounded memoize
On 9 Mar 2010, at 23:22, Michał Marczyk wrote: In the way of early feedback -- that's looks super neat! I've got this instant feeling that this would be a great clojure.contrib.memoize. +1 That would be wonderful. -- 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: bounded memoize
2010/3/10 Steve Purcell st...@sanityinc.com: On 9 Mar 2010, at 23:22, Michał Marczyk wrote: In the way of early feedback -- that's looks super neat! I've got this instant feeling that this would be a great clojure.contrib.memoize. +1 That would be wonderful. Well, in the way of early feedback too (alas not much time to argument in length), there are some points which annoy me : * usage of refs : I had a bad feeling, and cgrand confirmed this to me by pointing an even more interesting counter-argument. Me: using refs is not mandatory since you do not need to synchronize this change with anything else. Christophe: And by using refs, you synchronize the change with a potential uber STM transaction, and if this uber STM transaction retries, you will not benefit from the memoization, since the memoization itself will be discarded by the retry. * lookup function responsibilities: I cannot (yet) offer a better way to approach the problem, but I have a bad feeling with the lookup function changing things behind the scene. My 0.02 euros, -- Laurent -- 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.core/compare and persistent lists
On 10 March 2010 02:19, K. kotot...@gmail.com wrote: How should I compare two persistent lists ? Is it acceptable for you to use '=' user= (= '(1 2) '(3 4)) false user= (= '(1 2) '(1 2)) true or do you really really need the +1 0 -1 behavior? Is there any problem with ISeq requiring compareTo? In principal I think that should be fine tprat...@apis:~/projects/clojure$ clj Clojure 1.2.0-master-SNAPSHOT user= (compare '(1 2) '(3 4)) -1 user= (compare '(1 2) '(0 4)) 1 user= (compare (seq {:a 1}) (seq {:a 1})) 0 ;; though is it really meaningful to write something like: user= (compare (seq {:b 2, :a 1}) (seq {:a 1, :b 2})) 1 ;; I guess it doesn't matter much at the end of the day :) Attached is a patch to that effect. Happy to raise a ticket if this is welcome, and/or make a PersistentList only compareTo patch. Regards, Tim. -- 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=enFrom 633d8b03ecb304e94e43d41ef57eab8fbb354533 Mon Sep 17 00:00:00 2001 From: Timothy Pratley timothyprat...@gmail.com Date: Wed, 10 Mar 2010 22:14:13 +1100 Subject: [PATCH] Made ISeq Comparable --- src/jvm/clojure/lang/ASeq.java| 22 - src/jvm/clojure/lang/ISeq.java|4 ++- src/jvm/clojure/lang/LazySeq.java |7 - src/jvm/clojure/lang/PersistentList.java | 32 - test/clojure/test_clojure/data_structures.clj | 10 ++- 5 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/jvm/clojure/lang/ASeq.java b/src/jvm/clojure/lang/ASeq.java index 73f88da..baaed1e 100644 --- a/src/jvm/clojure/lang/ASeq.java +++ b/src/jvm/clojure/lang/ASeq.java @@ -12,7 +12,7 @@ package clojure.lang; import java.util.*; -public abstract class ASeq extends Obj implements ISeq, List, Streamable{ +public abstract class ASeq extends Obj implements ISeq, List, Streamable, Comparable{ transient int _hash = -1; public String toString(){ @@ -59,6 +59,26 @@ public boolean equals(Object obj){ } +public int compareTo(Object obj){ + + if(!(obj instanceof Sequential || obj instanceof List)) + throw new UnsupportedOperationException(); + ISeq ms = RT.seq(obj); + for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) + { + if(ms == null) + return 1; + int c = Util.compare(s.first(), ms.first()); + if ( c != 0 ) + return c; + } + if(ms == null) + return 0; + else + return -1; + +} + public int hashCode(){ if(_hash == -1) { diff --git a/src/jvm/clojure/lang/ISeq.java b/src/jvm/clojure/lang/ISeq.java index 6edb519..dbeb957 100644 --- a/src/jvm/clojure/lang/ISeq.java +++ b/src/jvm/clojure/lang/ISeq.java @@ -16,7 +16,7 @@ package clojure.lang; * ISeqs are immutable values, i.e. neither first(), nor rest() changes * or invalidates the ISeq */ -public interface ISeq extends IPersistentCollection, Sequential{ +public interface ISeq extends IPersistentCollection, Sequential, Comparable{ Object first(); @@ -26,4 +26,6 @@ ISeq more(); ISeq cons(Object o); +int compareTo(Object o); + } diff --git a/src/jvm/clojure/lang/LazySeq.java b/src/jvm/clojure/lang/LazySeq.java index a853e9b..2c2ecb4 100644 --- a/src/jvm/clojure/lang/LazySeq.java +++ b/src/jvm/clojure/lang/LazySeq.java @@ -14,7 +14,7 @@ package clojure.lang; import java.util.*; -public final class LazySeq extends Obj implements ISeq, List{ +public final class LazySeq extends Obj implements ISeq, List, Comparable{ private IFn fn; private Object sv; @@ -74,6 +74,11 @@ public int count(){ return c; } +public int compareTo(Object o){ + ISeq ms = RT.seq(o); + return seq().compareTo( ms ); +} + public Object first(){ seq(); if(s == null) diff --git a/src/jvm/clojure/lang/PersistentList.java b/src/jvm/clojure/lang/PersistentList.java index 477d1cb..5a0f1a2 100644 --- a/src/jvm/clojure/lang/PersistentList.java +++ b/src/jvm/clojure/lang/PersistentList.java @@ -12,7 +12,7 @@ package clojure.lang; import java.util.*; -public class PersistentList extends ASeq implements IPersistentList, IReduce, List, Counted{ +public class PersistentList extends ASeq implements IPersistentList, IReduce, List, Counted, Comparable{ private final Object _first; private final IPersistentList _rest; @@ -124,6 +124,27 @@ public Object reduce(IFn f, Object start) throws Exception{ return ret; } +public int compareTo(Object o){ + PersistentList ll = (PersistentList) o; + if(count() ll.count()) + return -1; + else if(count() ll.count()) + return 1; + ISeq ms = RT.seq(o); + for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) + { + if(ms == null) + return 1; + int c
Re: recursive call boxing primitives?
Oops, sorry, I thought my post was stuck in the moderation queue and have only just noticed the replies while browsing through the list history! Thanks to everyone who replied. Your version looks to be about six times faster than mine was. Thanks ever so much! In fact I wouldn't have noticed the difference between it and the scala version by eye. Having got interested I'll try to do proper timings. Would anyone be interested in the results? Cheers, John. On Mar 2, 6:56 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: Hi John, You can get some speedup by using unboxed math in draw-tree (see below). What kind of speed difference are you seeing? Stu (import '(javax.swing JFrame JPanel ) '(java.awt Color Graphics Graphics2D)) (defn draw-tree [ #^Graphics g2d angle x y length branch-angle depth] (when ( depth 0) (let [angle (double angle) x (double x) y (double y) length (double length) branch-angle (double branch-angle) depth (double depth) new-x (- x (* length (Math/sin (Math/toRadians angle new-y (- y (* length (Math/cos (Math/toRadians angle new-length (fn [] (* length (+ 0.75 (rand 0.1 new-angle (fn [op] (op angle (* branch-angle (+ 0.75 (rand)] (. g2d drawLine x y new-x new-y) (draw-tree g2d (new-angle +) new-x new-y (new-length) branch- angle (- depth 1)) (draw-tree g2d (new-angle -) new-x new-y (new-length) branch- angle (- depth 1) (defn render [ #^Graphics g w h] (doto g (.setColor (Color/BLACK)) (.fillRect 0 0 w h) (.setColor (Color/GREEN))) (let [init-length ( / (min w h) 5), branch-angle (* 10 (/ w h)), max-depth 12] (draw-tree g 0.0 (/ w 2) h init-length branch-angle max-depth))) (defn create-panel [] Create a panel with a customised render (proxy [JPanel] [] (paintComponent [g] (proxy-super paintComponent g) (time (render g (. this getWidth) (. this getHeight)) (defn run [] (let [frame (JFrame. Clojure Fractal Tree) panel (create-panel)] (doto frame (.add panel) (.setSize 640 400) (.setVisible true (run) Hi, the other day I was at a conference in London and learned Scala. As my first program I translated a favourite fractal tree program (which I stole from:http://marblemice.com/2009/04/26/clojure-fractal-tree/) . The programs are almost exactly the same in the two languages. The Scala version seems quite a lot faster than the Clojure one. I added type hints for the Graphics objects, but there's also a reflection warning from the JPanel proxy, which I think is unimportant, but which I can't see how to get rid of. Is the reason the Clojure version is slow that recursive calls to draw- tree are boxing and unboxing primitive types? If so is there anything that can be done? Did I just pick a particularly bad example program? Or am I just missing something silly? Is there an easy way to examine the byte-code? Is it human-readable? Can it be done from a REPL like disassemble in Lisp? --- clojure version (import '(javax.swing JFrame JPanel ) '(java.awt Color Graphics Graphics2D)) (defn draw-tree [ #^Graphics g2d angle x y length branch-angle depth] (if ( depth 0) (let [new-x (- x (* length (Math/sin (Math/toRadians angle new-y (- y (* length (Math/cos (Math/toRadians angle new-length (fn [] (* length (+ 0.75 (rand 0.1 new-angle (fn [op] (op angle (* branch-angle (+ 0.75 (rand)] (. g2d drawLine x y new-x new-y) (draw-tree g2d (new-angle +) new-x new-y (new-length) branch- angle (- depth 1)) (draw-tree g2d (new-angle -) new-x new-y (new-length) branch- angle (- depth 1) (defn render [ #^Graphics g w h ] (doto g (.setColor (Color/BLACK)) (.fillRect 0 0 w h) (.setColor (Color/GREEN))) (let [init-length ( / (min w h) 5), branch-angle (* 10 (/ w h)), max-depth 12] (draw-tree g 0.0 (/ w 2) h init-length branch-angle max-depth))) (defn create-panel [] Create a panel with a customised render (proxy [JPanel] [] (paintComponent [g] (proxy-super paintComponent g) (render g (. this getWidth) (. this getHeight) (defn run [] (let [frame (JFrame. Clojure Fractal Tree) panel (create-panel)] (doto frame (.add panel) (.setSize 640 400) (.setVisible true (run) --- scala version import scala.swing._ import java.awt._ import javax.swing._ object ScalaFractalTree { def main(args: Array[String]){ val frame=new JFrame(Scala Fractal Tree)
Re: What's an idiomatic translation of this CL data structure?
CL's defparameter corresponds to plain def. There is a level of structure you are not representing: alternatives. Here is what I'd use: :sentence [[:noun-phrase :verb-phrase]] ... :article [the a] ... The string literals are the implicit terminals and are thus easy to distinguish. An article isn't a terminal since it has multiple alternatives. -Per On Wed, Mar 10, 2010 at 12:47 PM, Mike K mbk.li...@gmail.com wrote: In PAIP section 2.3, Norvig gives an example of a generative grammar: ;; common lisp (defparameter *simple-grammar* '((sentence - (noun-phrase verb-phrase)) (noun-phrase - (Article Noun)) (verb-phrase - (Verb noun-phrase)) (Article - the a) (Noun - man ball woman table) (Verb - hit took saw liked)) A grammar for a trivial subset of English.) What's the most idiomatic way to write something like this in Clojure? My first attempt is as follows: (defonce- *simple-grammar* {:sentence [:noun-phrase :verb-phrase] :noun-phrase [:Article :Noun] :verb-phrase [:Verb :noun-phrase] :Article '(the a) :Noun '(man ball woman table) :Verb '(hit took saw liked)} A grammar for a trivial subset of English.) Assume I'm going to need some way to distinguish terminals from non- terminals. Above I used lists vs vectors. If this were a non-toy app where I was optimizing for performance, would it make more sense to use vectors everywhere? If so, what would be a good succinct way to differentiate the two rule types? Could I add meta-data to the vector literals somehow? Or perhaps use structs instead? Thanks, Mike -- 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
REPL, refs and casting
I am seeing a difference in running the contents of a function vs. running the function by name in a REPL. I am writing a simple blackjack game in Clojure, and have a ref called 'cards' for representing the state of the game. I initialize it this way: user (dosync (alter cards assoc :deck (build-deck card-values card-suits) :house (list) :player (list))) {:deck ((8 \S) (2 \C) (6 \C) (8 \D) (6 \H) (\A \H) (8 \C) (7 \H) (\A \C) (2 \D) (\K \H) (10 \D) (4 \H) (6 \S) (2 \H) (\Q \H) (3 \D) (10 \S) (3 \S) (1 \S) (\A \D) (9 \H) (\J \S) (4 \D) (1 \C) (\K \D) (2 \S) (1 \H) (5 \C) (\K \C) (10 \H) (9 \D) (9 \C) (\J \D) (\Q \C) (7 \S) (7 \D) (9 \S) (1 \D) (\J \H) (10 \C) (6 \D) (\K \S) (5 \H) (\J \C) (7 \C) (4 \C) (\Q \D) (\Q \S) (5 \D) (\A \S) (3 \C) (3 \H) (4 \S) (8 \H) (5 \S)), :player (), :house ()} I have defined the following function to deal cards from the deck to the player, (defn deal ([] (dosync (alter cards assoc :deck (build-deck card-values card-suits) :house (list) :player (list))) (deal 2 :player) (deal 2 :house)) ([n hand] (dosync (alter cards assoc hand (concat (get @cards hand) (take n (get @cards :deck))) :deck (take-last (- (count (get @cards :deck)) n) (get @cards :deck)) Now, the two-parameter version of this function works when I initialize cards and invoke the code manually, user (let [n 2 hand :house] (dosync (alter cards assoc hand (concat (get @cards hand) (take n (get @cards :deck))) :deck (take-last (- (count (get @cards :deck)) n) (get @cards :deck) {:deck ((6 \C) (8 \D) (6 \H) (\A \H) (8 \C) (7 \H) (\A \C) (2 \D) (\K \H) (10 \D) (4 \H) (6 \S) (2 \H) (\Q \H) (3 \D) (10 \S) (3 \S) (1 \S) (\A \D) (9 \H) (\J \S) (4 \D) (1 \C) (\K \D) (2 \S) (1 \H) (5 \C) (\K \C) (10 \H) (9 \D) (9 \C) (\J \D) (\Q \C) (7 \S) (7 \D) (9 \S) (1 \D) (\J \H) (10 \C) (6 \D) (\K \S) (5 \H) (\J \C) (7 \C) (4 \C) (\Q \D) (\Q \S) (5 \D) (\A \S) (3 \C) (3 \H) (4 \S) (8 \H) (5 \S)), :player (), :house ((8 \S) (2 \C))} but calling (deal 2 :house) bombs out with the following stacktrace: clojure.lang.Ref cannot be cast to clojure.lang.Associative [Thrown class java.lang.ClassCastException] Restarts: 0: [ABORT] Return to SLIME's top level. Backtrace: 0: clojure.lang.RT.assoc(RT.java:666) 1: clojure.core$assoc__4268.invoke(core.clj:144) 2: clojure.core$assoc__4268.doInvoke(core.clj:146) 3: clojure.lang.RestFn.invoke(RestFn.java:483) 4: user$deal__2081$fn__2084.invoke(NO_SOURCE_FILE:55) 5: clojure.lang.AFn.call(AFn.java:31) 6: clojure.lang.LockingTransaction.run(LockingTransaction.java:263) 7: clojure.lang.LockingTransaction.runInTransaction(LockingTransaction.java:231) 8: user$deal__2081.invoke(NO_SOURCE_FILE:55) 9: user$eval__3276.invoke(NO_SOURCE_FILE:1) 10: clojure.lang.Compiler.eval(Compiler.java:4642) 11: clojure.core$eval__5254.invoke(core.clj:2031) 12: swank.commands.basic$eval_region__907.invoke(basic.clj:40) 13: swank.commands.basic$eval_region__907.invoke(basic.clj:31) 14: swank.commands.basic$eval__927$listener_eval__929.invoke(basic.clj:54) 15: clojure.lang.Var.invoke(Var.java:359) 16: user$eval__3273.invoke(NO_SOURCE_FILE) 17: clojure.lang.Compiler.eval(Compiler.java:4642) 18: clojure.core$eval__5254.invoke(core.clj:2031) 19: swank.core$eval_in_emacs_package__455.invoke(core.clj:59) 20: swank.core$eval_for_emacs__533.invoke(core.clj:128) 21: clojure.lang.Var.invoke(Var.java:367) 22: clojure.lang.AFn.applyToHelper(AFn.java:179) 23: clojure.lang.Var.applyTo(Var.java:476) 24: clojure.core$apply__4379.invoke(core.clj:434) 25: swank.core$eval_from_control__458.invoke(core.clj:66) 26: swank.core$eval_loop__461.invoke(core.clj:71) 27: swank.core$spawn_repl_thread__595$fn__627$fn__629.invoke(core.clj:183) 28: clojure.lang.AFn.applyToHelper(AFn.java:171) 29: clojure.lang.AFn.applyTo(AFn.java:164) 30: clojure.core$apply__4379.invoke(core.clj:434) 31: swank.core$spawn_repl_thread__595$fn__627.doInvoke(core.clj:180) 32: clojure.lang.RestFn.invoke(RestFn.java:402) 33: clojure.lang.AFn.run(AFn.java:37) 34: java.lang.Thread.run(Thread.java:619) Any ideas? This feels like a really dumb question, but I've been poking at this for two days and can't figure it out. Mike -- 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: Visual Studio plugin
It does it matter to me how it gets written (C# or ClojureCLR) The desire is to have a plugin that supports syntax highlighting, completion, debugging, etc. but what I really am looking for is something that can manage repl(s) that can load the libraries for a given solution or set of projects (similar to what the Enclojure plugin does in Netbeans). Roadmap: 1. Have a REPL window running within VS that has history (preferably persistant across restarts), and can see a set of selected libs. The libs could come from the solution or some other way of setting up a context for REPLs. 2. Have the plugin know about Clojure files. Syntax highlighting, completion, folding, etc. 3. Debugger support Eric On Mar 9, 1:47 pm, mmwaikar mmwai...@gmail.com wrote: Forgot to ask the below mentioned questions earlier - Which version of Visual Studio are you targeting - 2008 or 2010? Do you have a development road-map for your plug-in features? Thanks, Manoj. On Mar 9, 1:05 pm, mmwaikar mmwai...@gmail.com wrote: Is it possible to write a plug-in in Clojure CLR? And if it is, would you prefer it in Clojure CLR or C# is fine? Also do you want both REPL and syntax highlighting for clj files in Visual Studio? Thanks, Manoj. On Mar 8, 2:17 pm, Eric Thorsen ethor...@enclojure.org wrote: Is there/is anyone working on/is anyone interested in working on a Visual Studio plugin for a Clojure REPL for clojureCLR? My company might be interested in sponsoring this work. Thanks! eric -- 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: Leiningen, Clojure and libraries: what am I missing?
On Mar 4, 7:33 am, Jan Rychter j...@rychter.com wrote: I haven't hacked on new Clojure stuff for the past two months or so. Now, having updated my repositories, I find that everybody just dropped ant and moved to leiningen. I tried to make sense of things, but can't. I must be missing something big here. [...] How do people deal with this? Here's how I do it. We've got five people in different places with different systems writing code for a dozen projects, of which five are Clojure projects. We use a common git server for coordination. Our standard project layout places all five Clojure projects as siblings in a common directory, along with a directory called xglib that contains common libraries. We tried leiningen, and it's appealing in some ways, but it makes too many assumptions about the way projects are organized, and its habit of downloading scads of jars quickly became annoying. We have five projects with partially-overlapping dependencies, some of which have others as dependencies. It was tiresome always to have multiple redundant copies of the same jars all over the place, so instead we created the common xglib directory, which is a sibling of the projects, and which contains all the libraries used by them. We use NetBeans as our standard IDE, not because I like it (I don't like any current-generation IDE) but because it works, and telling new contributors how to set it up to work with our projects is easy. So each project is, in fact, a NetBeans project. We also use Emacs, because a couple of use hate it slightly less than we hate NetBeans. We have a custom variant of swank-clojure-project (just a couple of function definitions, really) that knows how to find our common libraries directory and add all the jars in it to the CLASSPATH before running the Clojure REPL. It's also possible to use other editors (TextMate, for example) with this setup. The standard way we do builds is with NetBeans, but we can also do them with ant. It's not great, but it works, and it stays out of our way better than anything else we've tried so far. A couple of us are old Lisp hackers with memories of things like SK8 and Leibniz and MCL and SPE and Genera, so grumbling is ongoing, but we must adapt to the times we live in. -- 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
collections within collections
I am working on the following problem: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000 My strategy is to produce a series of triplets of a^2 + b^2 and then filter out the ones where the c^2 is a perfect square, in order to determine Pythagorean triplets. I wrote a function to produce triplets that takes a range as input: (use '[clojure.contrib.math :only (sqrt)]) (defn trips [coll] (loop [a (first coll) b (rest coll) trip []] (cond (seq b) (recur (first b) (rest b) (conj trip (map #(vector a % (sqrt (+ (* a a) (* % % b))) true trip))) ,so if I want to see all triplets over the range of 1-7, I just do: (trips (range 1 7)), which yields the following; [([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219]) ([2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759]) ([3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369]) ([4 5 6.4031242374328485] [4 6 7.211102550927978]) ([5 6 7.810249675906654])] Obviously the only Pythagorean triplet burried in there is 3, 4, 5. Now, I can easily test a single vector for integers as follows: (map integer? [5 6 7]) However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. I guess I need to use some functions for merging collections? Any help apprectiated. thanks!! -- 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
difficulty with becoming a contributor
I have some patches I'd like to submit, but I'm having trouble with the submission process. I've sent in a CA, and my name is on the contributor list (at http://clojure.org/contributing), but I still can't submit tickets on Assembla, and my membership to clojure-dev is still pending. Do I need to nudge someone to get my memberships approved, or should I just chill and wait for Rich to get around to 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: difficulty with becoming a contributor
On Wed, Mar 10, 2010 at 1:31 PM, John R. Williams j...@pobox.com wrote: I have some patches I'd like to submit, but I'm having trouble with the submission process. I've sent in a CA, and my name is on the contributor list (at http://clojure.org/contributing), but I still can't submit tickets on Assembla, and my membership to clojure-dev is still pending. Do I need to nudge someone to get my memberships approved, or should I just chill and wait for Rich to get around to it? I had this problem for a long time. I think you need to fill out some of the personal information on Assembla. After you log in, click on the Profile tab and fill that data in. Once I did that, I could at least open tickets. Brian -- 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: collections within collections
you can define a function to filter the result like (defn answer? [x] (filter #(every? integer? %) x)) and then just call it by doing user= (map #(answer? %) (trips (range 1 7))) (() () ([3 4 5]) () ()) On Wed, Mar 10, 2010 at 1:20 PM, Glen Rubin rubing...@gmail.com wrote: I am working on the following problem: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000 My strategy is to produce a series of triplets of a^2 + b^2 and then filter out the ones where the c^2 is a perfect square, in order to determine Pythagorean triplets. I wrote a function to produce triplets that takes a range as input: (use '[clojure.contrib.math :only (sqrt)]) (defn trips [coll] (loop [a (first coll) b (rest coll) trip []] (cond (seq b) (recur (first b) (rest b) (conj trip (map #(vector a % (sqrt (+ (* a a) (* % % b))) true trip))) ,so if I want to see all triplets over the range of 1-7, I just do: (trips (range 1 7)), which yields the following; [([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219]) ([2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759]) ([3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369]) ([4 5 6.4031242374328485] [4 6 7.211102550927978]) ([5 6 7.810249675906654])] Obviously the only Pythagorean triplet burried in there is 3, 4, 5. Now, I can easily test a single vector for integers as follows: (map integer? [5 6 7]) However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. I guess I need to use some functions for merging collections? Any help apprectiated. thanks!! -- 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 -- Omnem crede diem tibi diluxisse supremum. -- 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: collections within collections
Hi Glen, When your are working with infinite sets in Clojure, is it better to take advantage of laziness as far as possible, instead of passing limits such as the coll argument to trips. Here's how I would think about this problem: (defn pairs-adding-to-n Pairs of distinct positive integers that sum to n. [n] (for [x (range 1 (quot (inc n) 2))] [x (- n x)])) (defn pairs Lazy sequence of all pairs of distinct positive integers, in nondecreasing order by sum of the pair. [] (apply concat (map pairs-adding-to-n (iterate inc 1 (defn pythagorean-triples Lazy sequence of pythagorean triples [] (- (pairs) (map (fn [[a b]] [a b (sqrt (+ (* a a) (* b b)))])) (filter (fn [[a b c]] (integer? c) ;; only apply the limit (e.g. first) when asking the final question (first (filter (fn [args] (= 1000 (apply + args))) (pythagorean-triples))) Stu I am working on the following problem: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000 My strategy is to produce a series of triplets of a^2 + b^2 and then filter out the ones where the c^2 is a perfect square, in order to determine Pythagorean triplets. I wrote a function to produce triplets that takes a range as input: (use '[clojure.contrib.math :only (sqrt)]) (defn trips [coll] (loop [a (first coll) b (rest coll) trip []] (cond (seq b) (recur (first b) (rest b) (conj trip (map #(vector a % (sqrt (+ (* a a) (* % % b))) true trip))) ,so if I want to see all triplets over the range of 1-7, I just do: (trips (range 1 7)), which yields the following; [([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219]) ([2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759]) ([3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369]) ([4 5 6.4031242374328485] [4 6 7.211102550927978]) ([5 6 7.810249675906654])] Obviously the only Pythagorean triplet burried in there is 3, 4, 5. Now, I can easily test a single vector for integers as follows: (map integer? [5 6 7]) However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. I guess I need to use some functions for merging collections? Any help apprectiated. thanks!! -- 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: collections within collections
On Mar 10, 2010, at 12:20 PM, Glen Rubin wrote: However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. You can merge the structure into a single list of triples by applying concat: user= (def squares (apply concat (trips (range 1 7 #'user/squares user= squares ([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219] [2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759] [3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369] [4 5 6.4031242374328485] [4 6 7.211102550927978] [5 6 7.810249675906654]) Then test for perfect squares with this (assuming a and b are always integers): user= (defn perfect-square? [[a b c]] (integer? c)) #'user/perfect-square? user= (filter perfect-square? squares) ([3 4 5]) -- 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
Library for physical quantities, units, and dimensions
I have started working on a Clojure library for working with physical quantities that have units and dimensions. While there are still some important features missing, I consider the existing features sufficiently stable. The library requires the current master branch of the Clojure github repository, so it's for early adopters rather for friends of stable software. Check it out at http://code.google.com/p/clj-units/ Feedback welcome. Konrad. -- 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: Library for physical quantities, units, and dimensions
great! That's one thing I miss from time to time from Haskell. Haskell has a physical unit library. On Wed, Mar 10, 2010 at 3:08 PM, Konrad Hinsen konrad.hin...@fastmail.net wrote: I have started working on a Clojure library for working with physical quantities that have units and dimensions. While there are still some important features missing, I consider the existing features sufficiently stable. The library requires the current master branch of the Clojure github repository, so it's for early adopters rather for friends of stable software. Check it out at http://code.google.com/p/clj-units/ Feedback welcome. Konrad. -- 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 -- Omnem crede diem tibi diluxisse supremum. -- 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
Interesting integer behavior
In a recent clojure: user= (class 2147483647) java.lang.Integer user= (class (inc 2147483647)) java.math.BigInteger user= (class (inc (inc 2147483647))) java.lang.Long user= This isn't *technically* a bug, but it is an odd behavior. Brian -- 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: difficulty with becoming a contributor
Hi, For Assembla, I first had to watch the Clojure space in order to post a ticket. (It's a confusing interface.) Though it explicitly told me I should, so perhaps that's not the problem you face. For posting on clojure-dev, I asked about it on IRC and Rich added me... I'm sure you can just email him. All the best, Tj On Mar 10, 7:31 pm, John R. Williams j...@pobox.com wrote: I have some patches I'd like to submit, but I'm having trouble with the submission process. I've sent in a CA, and my name is on the contributor list (athttp://clojure.org/contributing), but I still can't submit tickets on Assembla, and my membership to clojure-dev is still pending. Do I need to nudge someone to get my memberships approved, or should I just chill and wait for Rich to get around to 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: enclojure install killed netbeans 6.8
No, I moved the entire 6.8 directory out of .netbeans and it still didn't run. You still think I should focus on getting rid of just the clojure files? Netbeans can't just rebuild that directory seeing as it's not there anymore? Josh On Mar 9, 2:01 pm, Mark Nutter manutte...@gmail.com wrote: On Sun, Mar 7, 2010 at 6:44 PM, strattonbrazil strattonbra...@gmail.com wrote: I am on Linux. I have a 6.6 and a 6.8 directory in my .netbeans folder. 6.6 still runs. I have tried moving individual jars in and out of that dir, but I still get the error. I even moved the entire 6.8 dir and still get the same message. There's more than just jar files involved -- some of the .xml config files contain pointers that tell NetBeans to try to load whatever library it is that you are missing. If you want to completely remove the plugin, you need to get rid of all the clojure-related files in the .netbeans/6.8 directory. You can use the find command to locate them: $ find ~/.netbeans -name '*cloj*' -print Mark -- 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: collections within collections
I like Clojure, but as a point of comparison, here's a Haskell solution, as typed in the REPL: Prelude let bOf a = 1000*(500 - a)/(1000 - a) Prelude let nearInt x = x - fromInteger(truncate x) 0.01 Prelude head [ ( a, b, sqrt(a^2 + b^2) ) | a - [1..], b - [bOf a], nearInt b ] (200.0,375.0,425.0) The numbers in the result add up to 1000, of course. Here, I just solved b in terms of a, which is function bOf. Predicate nearInt detects whether its argument is an integer (or close enough). Haskell is lazy, so even though [1..] and the big list comprehension are infinite, head just needs the first element. -- 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: Software Training Center and Startup Incubator
Sorry I forgot to mention, please go to the site if you want to support, by thumbs up or comment. There is a 100,000 euro prize and 500,000 euro investment for the top two ideas, I think this money would go a long way to further fund the development of clojure and Lisp aboption. On Mar 10, 10:37 pm, startup jennifermorgan2...@gmail.com wrote: I have entered the above idea into a national idea's competition being run in Ireland at the moment.www.yourcountryyourcall.com id=D2604 I am proposing the following: I would like to propose a model for the development of a new software center that focuses on a long forgotten computer language namely LISP (50 years old). Or to be more specific a more recent implementation that runs on the Java framework that goes by the name clojurehttp://clojure.org/. The software centers main purpose is to help bootstrap web based start- ups by giving them a place to develop their companies with a small up front grant/board and lodgings - similar tohttp://ycombinator.com/in return for a small stake (1%) Better than any pension fund ;-). The software center would try to steer the candidates to use Lisp/ Clojure over other languages because of the flexibility and speed with with ideas can be developed and the languages inherent suitability for large Web Scale/Cloud apps and AI. Also the software center would be open to anyone with or without programming experience or qualification ,because the ideas and methods of software development using Lisp are so opposite to the conventional languages that it would not be deemed a handicap not have programmed before, at all. And besides the software center main reason for existence is to encourage non-linear thinking. All training would be based on the famous MIT introductory videos. Where students finish by designing their own computer languages.http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures . Lets make Ireland the Intelligent Software Country -- 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 for financial applications
On Mar 8, 5:50 pm, Jonathan Shore jonathan.sh...@gmail.com wrote: Now OO may be antithetical to the traditional way of using lisp, however, I see myself needing something close to an OO-style mapping for part of what I do. Currently my trading strategies have large and disparate state contained in each strategy. I'm not really sure how can effeciently map into clojure. So for instance if I have 50 different pieces of state, some of which will be: - matrices - numbers - vectors - booleans - FSMs How would I encapsulate this into a data structure to be passed into functions efficiently? I could use a map of symbols to various structures, but that would be inefficient in access and memory. It's not really clear what the problem is. If the state is going to stick around for a while and you expect to mutate it then use reference types and keep the variables in namespaces next to the code that operates on them. In the same way that you group your code with your member and class variables when defining a class, you can group your code with the state variables in your namespaces. You can use maps to organize groups of related data, and if you want to update nested parts of this data without having to create new maps all the time you can have the map store refs or atoms that you can mutate safely. Shifting from OO does take a bit of squinting and experimentation, at least it did for me after doing a lot of Ruby and C ++, but now I find that by having my data sitting in the open in standard data structures it lets me experiment and re-use methods much easier without needing to deal with useless machinery. - does small computations at high frequency - pushes a huge amount of data through at each timestep - currently can take hours or days to run with mutation. It will really depend on the nature of the mutation. With some algorithms you can probably optimize the inner loops with type hints, transients, unboxed numbers and raw arrays and get performance on par with Java. I was experimenting with real-time 2D animation in Clojure a while back, and mutating pixel buffers was not a great fit. Anyway, going to Java or even C++ is damn easy from Clojure, so give it a shot and in the worst case you can use Clojure as the glue for a library of lower level algorithms written in whatever you want. -Jeff -- 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: REPL in a browser
You mean Clojurescript? http://github.com/richhickey/clojure-contrib/tree/master/clojurescript/ It would be great to have more people working on it... On Mar 9, 12:12 pm, Jozef Wagner jozef.wag...@gmail.com wrote: Thank you. They seem to use java to generate (with GWT) both client-side html and javascript, and server-side REPL. Nice approach. I'm looking forward to the day when one will be able to do all that only with clojure :) We already have a nice clojrue web frameworks, so the only thing that is missing IMO is clojure to javascript compiler. JW On Mar 7, 6:03 pm, Angel Java Lopez ajlopez2...@gmail.com wrote: There is a Clojure REPL in a browser implementation I know: http://lotrepls.appspot.com/ Project homehttp://code.google.com/p/lotrepls/ They support - beanshell * - clojure - groovy * - javascript * - python * - ruby * - scala * - scheme using Google App Engine as backend Angel Java Lopezhttp://www.ajlopez.comhttp://twitter.com/ajlopez On Sun, Mar 7, 2010 at 7:18 AM, Jozef Wagner jozef.wag...@gmail.com wrote: Hi, I'm wondering how hard it would be to make a clojure REPL accessible from a browser. Something like athttp://www.simplyscala.com/ Some approaches I have thought of: a) Java Applet Downsides: need to have Java 1.6 enabled in a browser, less cool visual presentation :) Upsides (for some): Running locally on a client b) REPL on a server with javascript frontend UI would be handled with the javascript and the client would send inputs to the REPL sitting on the server. Downsides: Bigger load on the server, needs to secure the underlying JVM, so the users cannot access everything through the REPL. c) Clojurescript (running clojure REPL on top of the javascript) Is it even possible? Don't know what is the state of the clojurescript. This approach could be implemented so that REPL would run either on a client or on the server I think Any thoughts? Best, JW -- 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.comclojure%2bunsubscr...@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: enclojure install killed netbeans 6.8
I haven't tried removing the entire 6.8 directory (except in conjunction with a complete reinstall of NetBeans), so I can't say whether that should or should not work, but I have manually removed the enclojure plugin via deleting the clojure-specific files and that has gotten me out of a few jams. Beyond that I'm out of tricks. Good luck. Mark On Wed, Mar 10, 2010 at 3:55 PM, strattonbrazil strattonbra...@gmail.com wrote: No, I moved the entire 6.8 directory out of .netbeans and it still didn't run. You still think I should focus on getting rid of just the clojure files? Netbeans can't just rebuild that directory seeing as it's not there anymore? Josh On Mar 9, 2:01 pm, Mark Nutter manutte...@gmail.com wrote: On Sun, Mar 7, 2010 at 6:44 PM, strattonbrazil strattonbra...@gmail.com wrote: I am on Linux. I have a 6.6 and a 6.8 directory in my .netbeans folder. 6.6 still runs. I have tried moving individual jars in and out of that dir, but I still get the error. I even moved the entire 6.8 dir and still get the same message. There's more than just jar files involved -- some of the .xml config files contain pointers that tell NetBeans to try to load whatever library it is that you are missing. If you want to completely remove the plugin, you need to get rid of all the clojure-related files in the .netbeans/6.8 directory. You can use the find command to locate them: $ find ~/.netbeans -name '*cloj*' -print Mark -- 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: Leiningen, Clojure and libraries: what am I missing?
Since leiningen downloads everything to a local repo, can't we do away with copies and use symlinks if they are supported by the filesystem? I feel there should be an option for this. -Brent On Mar 4, 1:59 pm, David Nolen dnolen.li...@gmail.com wrote: On Thu, Mar 4, 2010 at 10:19 AM, Stuart Sierra the.stuart.sie...@gmail.comwrote: As many of you know, I've always been tepid on lein. I'd rather go with Maven whole-hog, because that offers the most robust model for incorporating Java libraries. If Lein evolves to to handle dependencies of dependencies and intelligently generates the classpath based on these dependencies (instead of copying files around) what advantage does Maven really have? 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
Re: REPL, refs and casting
On 10 March 2010 21:03, Mike Erickson mike.erick...@gmail.com wrote: but calling (deal 2 :house) bombs out with the following stacktrace: Hi Mike, I tried running your code and it worked fine for me... so I think something else is playing tricks on you here like maybe you changed the function in your text buffer but did not eval it (so it is running an old version)? Suggest you try it again with a fresh environment - maybe put the full code listing up on gist if you still can't get it working, as the code you included doesn't seem to exhibit a problem. Regards, Tim. user= (deal) {:player ([:deck [[8 \S] [2 \C] [6 \C] [8 \D] [6 \H] [\A \H] [8 \C] [7 \H] [\A \C] [2 \D] [\K \H] [10 \D] [4 \H] [6 \S] [2 \H] [\Q \H] [3 \D] [10 \S] [3 \S] [1 \S] [\A \D] [9 \H] [\J \S] [4 \D] [1 \C] [\K \D] [2 \S] [1 \H] [5 \C] [\K \C] [10 \H] [9 \D] [9 \C] [\J \D] [\Q \C] [7 \S] [7 \D] [9 \S] [1 \D] [\J \H] [10 \C] [6 \D] [\K \S] [5 \H] [\J \C] [7 \C] [4 \C] [\Q \D] [\Q \S] [5 \D] [\A \S] [3 \C] [3 \H] [4 \S] [8 \H] [5 \S]]] [:player []]), :house ([:house []]), :deck nil} user= (deal 2 :house) {:player ([:deck [[8 \S] [2 \C] [6 \C] [8 \D] [6 \H] [\A \H] [8 \C] [7 \H] [\A \C] [2 \D] [\K \H] [10 \D] [4 \H] [6 \S] [2 \H] [\Q \H] [3 \D] [10 \S] [3 \S] [1 \S] [\A \D] [9 \H] [\J \S] [4 \D] [1 \C] [\K \D] [2 \S] [1 \H] [5 \C] [\K \C] [10 \H] [9 \D] [9 \C] [\J \D] [\Q \C] [7 \S] [7 \D] [9 \S] [1 \D] [\J \H] [10 \C] [6 \D] [\K \S] [5 \H] [\J \C] [7 \C] [4 \C] [\Q \D] [\Q \S] [5 \D] [\A \S] [3 \C] [3 \H] [4 \S] [8 \H] [5 \S]]] [:player []]), :house ([:house []]), :deck nil} ;; NB I just used a stub build-deck that creates the deck in your original post. -- 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: REPL, refs and casting
On 11 March 2010 17:10, Timothy Pratley timothyprat...@gmail.com wrote: I tried running your code and it worked fine for me... Ah excuse me it only 'worked' because I used vectors instead of lists: [5 \S]]] [:player []]), :house ([:house []]), :deck nil} --- should give you the clue you need, You probably want to use conj instead of concat! Regards, Tim. -- 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: Leiningen, Clojure and libraries: what am I missing?
Hi, On Mar 11, 5:07 am, Brent Millare brent.mill...@gmail.com wrote: Since leiningen downloads everything to a local repo, can't we do away with copies and use symlinks if they are supported by the filesystem? I feel there should be an option for this. Why not adding the files from the repo directly to the classpath? Works everywhere and doesn't copy... 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: REPL, refs and casting
On 11 March 2010 17:15, Timothy Pratley timothyprat...@gmail.com wrote: You probably want to use conj instead of concat! Actually ignore that! I was being confused by the deck-building. Can you try running this code: http://gist.github.com/328912 It is exactly the same as yours but uses known starting conditions... and seems to give the behavior you are expecting. -- 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: Leiningen, Clojure and libraries: what am I missing?
Brent Millare brent.mill...@gmail.com writes: Since leiningen downloads everything to a local repo, can't we do away with copies and use symlinks if they are supported by the filesystem? I feel there should be an option for this. What benefit does this have aside from a tiny saving in disk space? The way it currently works has a number of benefits: * really simple and easy to understand! * you can tarball your project directory, rsync it another machine or whatever and everything you need will be right there. No need to worry about redownloading anything or copying your local maven cache around. * you can run stuff manually just with: java -cp 'src:classes:lib/*' clojure.main * really simple and easy to understand! (worth repeating) Doing tricks with symlinks or having lein set your classpath magically like Maven does just seems to be adding complexity for the sake of complexity. Cheers, 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: Leiningen, Clojure and libraries: what am I missing?
What benefit does this have aside from a tiny saving in disk space? Not that tiny when you multiply it across the dozens of projects on your hard drive. repos $ du -hc $(ls */lib/*.jar) | fgrep total 291Mtotal Add to that the size of the Maven repo itself. Symlinks are nice. * you can tarball your project directory, rsync it another machine or whatever and everything you need will be right there. No need to worry about redownloading anything or copying your local maven cache around. Unix is great. man tar: -h, --dereference don't dump symlinks; dump the files they point to -- 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: Leiningen, Clojure and libraries: what am I missing?
Richard Newman holyg...@gmail.com writes: What benefit does this have aside from a tiny saving in disk space? Not that tiny when you multiply it across the dozens of projects on your hard drive. repos $ du -hc $(ls */lib/*.jar) | fgrep total 291M total Cost (on standard disks): 5 cents. Sorry, that's tiny. It's even less than 0.5% of the small SSD I have in my laptop. Seriously, this is just premature optimization. -- 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: REPL, refs and casting
Hi Mike, On 10 March 2010 21:03, Mike Erickson mike.erick...@gmail.com wrote: I am writing a simple blackjack game in Clojure I've written up a little commentary as to how I'd approach this problem differently: http://gist.github.com/328929 which hopefully will give you some ideas. The general thrust being to keep your game logic functions separate from state manipulation as it makes the parts easier to understand and test. Regards, Tim. -- 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: bounded memoize
Hello Laurent, On Mar 10, 11:45 am, Laurent PETIT laurent.pe...@gmail.com wrote: * usage of refs : I had a bad feeling, and cgrand confirmed this to me by pointing an even more interesting counter-argument. Me: using refs is not mandatory since you do not need to synchronize this change with anything else. I don't think, that this is entirely true! You have to syncronise the cache with the state in the strategy. This can be done with atoms only if the cache and the strategy state are contained in the same atom and all updates happen in a single call to swap! (or reset!). As soon as you have multiple calls, you need transactions again, because the atom might change between the two calls. And you can't swap! and return a result at the same time. Say you have the LRU strategy. You deref the cache, find the result cached. Now you swap! in the new access time into your state. But between the deref and the swap! another call might trigger the removal of the entry. So you always have to guard against the atom suddenly changing underneath - even if it's only one atom. Something what annoys me more is that the computation may be fired of several times. Since the f is supposedly expensive, I'd rather avoid that. * lookup function responsibilities: I cannot (yet) offer a better way to approach the problem, but I have a bad feeling with the lookup function changing things behind the scene. Can you explain a little more on what you think is the problem? Things like LRU need some bookkeeping on access. Otherwise one just does not have the required information at hand and the strategy is not possible. So I think, you mean something else or you consider LRU a bad strategy. I have no experience with the different strategies, but I tend to believe the first possibility. If this is true you refer to the TTL strategy, where the lookup function is removing old entries. I also don't really like this. What are the possibilities? * removal in cache-update, may cause items to linger quite long in the cache depending on the call structure, possibly much longer than the TTL, still needs special handling in cache-lookup or out-of-date entries will be returned * removal in cache-lookup, happens (possibly) much more often * a dedicated thread, which is created when a new entry is done. Then sleeps for it's TTL and then wakes and removes the entry. This will however potentially create a lot of threads just sleeping around. I don't know how expensive this is. * a cron like thread, which sleeps to the next removal time, removes the out-of-date item for that point, sleeps again, and so on. This would be only one thread, but a more difficult implementation and requires cross-thread syncronisation. The cache-lookup provided the most bang for the buck if you want to keep it simple. Christophe: And by using refs, you synchronize the change with a potential uber STM transaction, and if this uber STM transaction retries, you will not benefit from the memoization, since the memoization itself will be discarded by the retry. This is a problem the STM cannot solve. We would need some dont-nest-me-dosync, which does not merge with a possible surrounding dosync. (This was actually part of the famous discussion between Rich and Cliff Click: How to define the borders of a transaction region?) I gave it another run and came up with another solution. Even more hairy. :P * a warm cache is fast * a cache miss is potentially slow, but the missing value is computed only once, multiple requests for the same item wait for the initially triggered computation * the cache can be updated (almost) in parallel for different items (defn memoize ([f] (memoize f naive-strategy)) ([f [cache-lookup cache-update]] (let [cache-state (atom {})] (fn [ args] (if-let [e (cache-lookup cache-state args)] @(val e) @(locking cache-state (if-let [e (cache-lookup cache-state args)] (val e) (let [result (promise)] (.start (Thread. #(deliver result (apply f args (swap! cache-state assoc-in [:cache args] result) (cache-update cache-state args) result But with this you can't reliably implement strategies like LRU and the like. But this is really an interesting problem. I'll mull a little more about it. :) 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: Leiningen, Clojure and libraries: what am I missing?
repos $ du -hc $(ls */lib/*.jar) | fgrep total 291Mtotal Cost (on standard disks): 5 cents. Sorry, that's tiny. It's even less than 0.5% of the small SSD I have in my laptop. Seriously, this is just premature optimization. You're seriously fine with every single Leiningen-based project spitting a redundant copy of Clojure, contrib, and whatever other dependencies it needs onto disk, and doing so every time it picks up a new snapshot? That every tiny library you pull off GitHub grabs another few dozen MB, rather than a few dozen KB? 290MB is only tiny if you have an empty disk. 290MB here, 290MB there, and suddenly the 13GB free on my 180GB laptop disk starts looking mighty cramped. I have a lot of stuff I'd rather store on that disk than 290MB of redundant jar copies. Those hundreds of megs get backed up, scanned, indexed, defragmented, yadda yadda. What a waste. You might also be overlooking disk caching, paging, JVM memory sharing, and other performance effects from having multiple instances of the same jars in memory. I know that the Mac JVM does some tricks to share memory in this way. Furthermore, it's slower to copy 28MB of jars than it is to symlink them: $ time cp -R lib /tmp/foo real0m2.981s user0m0.007s sys 0m0.152s ... surprise disk slowdown! All the nonsense of looking up snapshots, checking deps against the Maven repo, etc. already takes so much time that I dislike using Leiningen. Anything to bring that down by a few hundred milliseconds and a few fewer disk head slaps would be nice. There is no engineering reason to blindly copy jars into lib/. Hard links, symlinks, or computed classpaths are all better solutions in every single way. Premature optimization is the act of expending significant time addressing a performance problem prior to measurement, typically allowing unmeasured performance concerns to affect system design. Using symlinks instead of copying would not be a significant amount of work, doesn't affect the overall design, and we're hardly flying blind. You're using the wrong phrase. Here's a different Knuth quote: In established engineering disciplines a 12 % improvement, easily obtained, is never considered marginal and I believe the same viewpoint should prevail in software engineering I'd call this a decent improvement, and it's certainly easily obtained. Whatever happened to engineers building a decent solution out of a sense of pride, or even making the most basic half-assed attempt to conserve resources? Sometimes I despair. -- 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