Re: Speeding up equals using the cached hash code?

2010-08-05 Thread Nicolas Oury
That's might be an interesting trade-of to try. It is really good when big data structures are nearly equal. The comparison is linear but the comparaison once you know the hash is O(1) with a high probability. It is bad on very different structure, if you force a hash. Ideally, the equals method

Re: existing idiom for delaying a future ?

2010-08-05 Thread Meikel Brandmeyer
Hi Laurent, On Aug 5, 9:41 am, Laurent PETIT laurent.pe...@gmail.com wrote: Here is what I've come up in my head :  * create a datastructure with 2 fields, one holding a future, one holding a delay. the future will wait for n millisecs, and then force the delay.  * The datastructure will

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Meikel Brandmeyer m...@kotka.de Hi Laurent, On Aug 5, 9:41 am, Laurent PETIT laurent.pe...@gmail.com wrote: Here is what I've come up in my head : * create a datastructure with 2 fields, one holding a future, one holding a delay. the future will wait for n millisecs, and then

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
ok. Now one more question please: your solution looks also slightly more complex from the user's perspective: he has to deal with the *parser* object and the future object (returned by schedule-parse). So the question is: what does your solution provide that the sketch of my solution does not ?

Re: processing sequence/collection of functions

2010-08-05 Thread Moritz Ulrich
Functions are fist-class-objects in Clojure. You can pass them around just like every other object. You can even create anonymous functions and pass them to a function. (The function for anonymous functions is called fn) On Thu, Aug 5, 2010 at 7:10 AM, foop1 bsmd...@gmail.com wrote: Hmm

Re: existing idiom for delaying a future ?

2010-08-05 Thread Meikel Brandmeyer
Hi, On Aug 5, 11:34 am, Laurent PETIT laurent.pe...@gmail.com wrote: Now one more question please: your solution looks also slightly more complex from the user's perspective: he has to deal with the *parser* object and the future object (returned by schedule-parse). So the question is: what

Re: Speeding up equals using the cached hash code?

2010-08-05 Thread abhinav sarkar
If two objects are equal, they must have same hash code. But it does not imply the other way too. Two objects having the same hash code may be not equal (see, hash collision). So this approach may give false positives. - Abhinav On Thu, Aug 5, 2010 at 1:45 PM, Nicolas Oury nicolas.o...@gmail.com

Re: 2 links for beginners

2010-08-05 Thread faenvie
http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html a prophetic writing ... great ! thank you 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

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Laurent PETIT laurent.pe...@gmail.com Hello, My problem: the user types in the ccw's editor. Each time she types, there's an opportunity to reparse the editor's content. But the reparse is not always necessary, especially when the types a symbol. So I could use a delay to only

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Meikel Brandmeyer m...@kotka.de Hi, On Aug 5, 11:34 am, Laurent PETIT laurent.pe...@gmail.com wrote: Now one more question please: your solution looks also slightly more complex from the user's perspective: he has to deal with the *parser* object and the future object

Re: Speeding up equals using the cached hash code?

2010-08-05 Thread Laurent PETIT
2010/8/5 abhinav sarkar abhinav.sar...@gmail.com If two objects are equal, they must have same hash code. But it does not imply the other way too. Two objects having the same hash code may be not equal (see, hash collision). So this approach may give false positives. No, you didn't read the

Re: existing idiom for delaying a future ?

2010-08-05 Thread Meikel Brandmeyer
Hi, On Aug 5, 2:14 pm, Laurent PETIT laurent.pe...@gmail.com wrote: (ns delay.util) (defprotocol Cancellable (isCancelled [this]) (cancel [this])) (defn timed-delay [pause fun]   (let [d (delay (fun))         f (future (Thread/sleep pause) @d)]     (reify       clojure.lang.IDeref      

Re: Speeding up equals using the cached hash code?

2010-08-05 Thread Nicolas Oury
Just a quick follow-up. This is a big plus when you know (from meta reasons) that most successful equality tests will come from the identical? part of the test. Then you have most of the fail in O(1) by hashing and most of the successes in O(1) with identical?. While still being correct and

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Meikel Brandmeyer m...@kotka.de Hi, On Aug 5, 2:14 pm, Laurent PETIT laurent.pe...@gmail.com wrote: (ns delay.util) (defprotocol Cancellable (isCancelled [this]) (cancel [this])) (defn timed-delay [pause fun] (let [d (delay (fun)) f (future (Thread/sleep

Re: 2 links for beginners

2010-08-05 Thread Randy Hudson
Here's a nice commentary by fogus on Yegge's piece: http://blog.fogus.me/2009/02/06/yegge-clojure-arc-and-lolita-or-days-of-future-past/ For all intents and purposes, Clojure’s creator Rich Hickey is Arc’s Torvalds quipped on by Mr. Yegge. On Aug 5, 8:08 am, faenvie fanny.aen...@gmx.de wrote:

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Laurent PETIT laurent.pe...@gmail.com 2010/8/5 Meikel Brandmeyer m...@kotka.de Hi, On Aug 5, 2:14 pm, Laurent PETIT laurent.pe...@gmail.com wrote: (ns delay.util) (defprotocol Cancellable (isCancelled [this]) (cancel [this])) (defn timed-delay [pause fun] (let [d

Re: 2 links for beginners

2010-08-05 Thread faenvie
That is the most unsubstantiated, moronic piece of writing I've ever read in my life. I can't really tell what he's attacking, he's just swinging some dick-shaped sword around trying to hit stuff. i do not agree ... its clear that the article is a rant, does not go deep and misses

Re: existing idiom for delaying a future ?

2010-08-05 Thread Meikel Brandmeyer
Hi, On Aug 5, 2:47 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Yes, maybe I'm putting too much ... will need to think about it again I don't want to talk you into something. I just have a different view. But I don't understand your usage of the expression side-effect. Ok. Why do I

Re: Records can't be treated as functions anymore

2010-08-05 Thread Stuart Halloway
If records implemented IFn, you could treat them as collections, which they are not. There is an asymmetry here: Maps can be used as (impoverished but easy) records, but the reverse is not true: (:foo x); x is logically a record (though might be a map for simplicity). (x :foo)

Re: existing idiom for delaying a future ?

2010-08-05 Thread Meikel Brandmeyer
Woops. It's just in so far dependent, that it should parse the code again, when this was already triggered by a consumer. I mean't: it should *not* parse the code again ... -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: Records can't be treated as functions anymore

2010-08-05 Thread Laurent PETIT
2010/8/5 Stuart Halloway stuart.hallo...@gmail.com If records implemented IFn, you could treat them as collections, which they are not. Isn't the fact of making records associative for easing the use of treating them as collections ? user= (assoc (user.R. 1) :b 2) #:user.R{:a 1, :b 2} user=

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Meikel Brandmeyer m...@kotka.de Hi, On Aug 5, 2:47 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Yes, maybe I'm putting too much ... will need to think about it again I don't want to talk you into something. I just have a different view. But I don't understand your usage of

Programming Clojure: Snake: update-positions: What does the do do here?

2010-08-05 Thread michele
ORIGINAL (defn update-positions [snake apple] (dosync (if (eats? @snake @apple) (do (ref-set apple (create-apple)) (alter snake move :grow)) (alter snake move))) nil) WITHOUT do (defn update-positions [snake apple] (dosync (if (eats? @snake @apple)

Re: Records can't be treated as functions anymore

2010-08-05 Thread Steve Molitor
Maybe Im just getting stuck on semantics, but I'm confused. If maps are collections, and records function as maps, aren't records also collections? Steve On Thu, Aug 5, 2010 at 8:52 AM, Stuart Halloway stuart.hallo...@gmail.comwrote: If records implemented IFn, you could treat them as

Re: Programming Clojure: Snake: update-positions: What does the do do here?

2010-08-05 Thread Meikel Brandmeyer
Hi, On Aug 5, 4:18 pm, michele michelemen...@gmail.com wrote: ORIGINAL (defn update-positions [snake apple]   (dosync     (if (eats? @snake @apple)       (do (ref-set apple (create-apple))         (alter snake move :grow))      (alter snake move))) nil) WITHOUT do (defn

Re: Programming Clojure: Snake: update-positions: What does the do do here?

2010-08-05 Thread Peter Schuller
ORIGINAL (defn update-positions [snake apple]  (dosync    (if (eats? @snake @apple)      (do (ref-set apple (create-apple))        (alter snake move :grow))     (alter snake move))) nil) WITHOUT do (defn update-positions [snake apple]  (dosync    (if (eats? @snake @apple)      

Re: Speeding up equals using the cached hash code?

2010-08-05 Thread Paul Stadig
I believe the code already does what you are asking about. Are you talking about something like this? http://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/APersistentMap.java#L57 this? http://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/APersistentSet.java#L58 and

Re: Records can't be treated as functions anymore

2010-08-05 Thread Stuart Halloway
In a word, no. :-) Records and maps share an API. Maps can be used as anonymous records. Records generally should not be used as maps. My address information is a record (whether you bother to create Address or just throw it into a plain ol' map). Everyone's address information keyed by SSN

Re: Programming Clojure: Snake: update-positions: What does the do do here?

2010-08-05 Thread Laurent PETIT
2010/8/5 michele michelemen...@gmail.com ORIGINAL (defn update-positions [snake apple] (dosync (if (eats? @snake @apple) (do (ref-set apple (create-apple)) (alter snake move :grow)) (alter snake move))) nil) WITHOUT do (defn update-positions [snake apple]

Re: Programming Clojure: Snake: update-positions: What does the do do here?

2010-08-05 Thread Stuart Halloway
Adding to what Meikel said: A warning sign that the latter version is incorrect is the double open parens: ((ref-set ... Double open parens are fairly rare in Clojure code. Stu Hi, On Aug 5, 4:18 pm, michele michelemen...@gmail.com wrote: ORIGINAL (defn update-positions [snake apple]

Re: java.lang.OutOfMemoryError

2010-08-05 Thread Peter Schuller
the entire sequence being in memory. However, if you retain the head of the sequence elsewhere, you will see the same effect. I don't think my function retains the head?  Please correct me if I am wrong. Not that I can see but I don't have the full context. I tried reproducing just now and I

clojure compiler

2010-08-05 Thread Islon Scherer
Ok, this question is not about clojure itself, just a doubt I have. Clojure uses the ASM library to compile code to jvm bytecode. Let's suppose I created the foo.clj and bar.clj source files. The ns foo in foo.clj depends on the functions of bar in bar.clj. How the compiler manages file

(java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]

2010-08-05 Thread Dave
Hi, I don't understand why this doesn't work: (ns dpa (:gen-class) (:use [incanter.core :only ( matrix )] [clojure.core :only ( defn doseq line-seq println with-open )] [clojure.contrib.string :only ( blank? substring? )] (:import (java.io BufferedReader FileReader)))

Re: 2 links for beginners

2010-08-05 Thread Tim Daly
Steve Yegge is badly mis-informed. Large real programs have been written entirely in lisp. I am the lead developer on Axiom which is a very large lisp project (about 1 million things of code) to do computer algebra. The help system and graphics were implemented in C but browsers did not exist at

Hiring Clojure developers at Runa

2010-08-05 Thread George Jahad
Check us out here: http://www.workatruna.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

Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]

2010-08-05 Thread Nikita Beloglazov
Hi, Dave Why do you use 2 parenthesis before with-open in the first variant? And, as I know, it's not good practice to use def inside functions. Use let instead. I also advice you to split your program to smaller functions. Can you describe, what your program must do? Because don't understand :(

Re: 2 links for beginners

2010-08-05 Thread Tim Daly
faenvie wrote: That is the most unsubstantiated, moronic piece of writing I've ever read in my life. I can't really tell what he's attacking, he's just swinging some dick-shaped sword around trying to hit stuff. i do not agree ... its clear that the article is a rant, does not go

Re: 2 links for beginners

2010-08-05 Thread Martin DeMello
On Fri, Aug 6, 2010 at 12:31 AM, Tim Daly d...@axiom-developer.org wrote: Measure your OODA loop in all the languages you know. See which one cycles fastest. I'd bet that's your favorite language. Excellent observation! Definitely explains why, for all its lack of performance and minor quirks,

Converting a AS3 Cave Generator to Clojure

2010-08-05 Thread msappler
Hi I am having trouble with converting this cave generator to clojure. Basically how would you implement the generateCave method with pop and push in a functional style? Here is a description to the algorithm: http://properundead.com/2009/03/cave-generator.html And here you can download the AS3

Re: Speeding up equals using the cached hash code?

2010-08-05 Thread sune.simonsen
Thanks for all the answers. It is a little bit embarrassing, but Paul Stadig seems to be totally right, it is already implemented. I don't know how I could have overlooked that - sorry. I guess it is not that bad of an idea after all then ;-) I'll be a little more thorough next time I post. Kind

Error trying to use a GroovyShell from clojure

2010-08-05 Thread Chris Goellner
Hello all, long time listener first time caller. I've got a situation where I'm trying to apply some Groovy code against a clojure hashmap. I've got: (ns neat (:import (java.sql Timestamp) (groovy.lang Binding GroovyShell) (oracle.sql TIMESTAMP Datum)

Seattle Clojure meeting tonight

2010-08-05 Thread Phil Hagelberg
If you're in the Seattle area and interested in Clojure, come on by tonight! We are generally discussion- and code-centric rather than having presentations. All experience levels welcome, even if you're just curious. We are meeting at University Zoka at 7pm:

Re: existing idiom for delaying a future ?

2010-08-05 Thread Kyle Schaffrick
On Thu, 5 Aug 2010 16:05:07 +0200 Laurent PETIT laurent.pe...@gmail.com wrote: My point was that by providing different interfaces/protocols to different users, it's more an implementation detail than anything else if they have the same object or not. I don't expect my users to program on

Re: Error trying to use a GroovyShell from clojure

2010-08-05 Thread Wilson MacGyver
can you compile the groovy script to .class via groovyc? then you can use the groovy code within clojure via java interop. On Thu, Aug 5, 2010 at 2:33 PM, Chris Goellner cgoell...@gmail.com wrote: Hello all, long time listener first time caller. I've got a situation where I'm trying to apply

Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]

2010-08-05 Thread Dave
Thanks for the extra parentheses catch. I just noticed that while working on a different function (after hours of trying to figure it out). The program is reading in a pdb file line-by-line. I only want the xyz-coordinates of carbon atoms, avoiding any repeats when the coordinate of an atom is

Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]

2010-08-05 Thread Nikita Beloglazov
See my variant of your application: https://gist.github.com/efdb66487e899446332f I don't know if it works, because I can't test :( My thoughts about your example You shouldn't think about this procedure as about procedure where you use loop, like in other imperative languages with mutable data.

Re: Resource cleanup when lazy sequences are finalized

2010-08-05 Thread David Andrews
On Aug 3, 5:28 pm, Jeff Palmucci jpalmu...@gmail.com wrote: See my library athttp://github.com/jpalmucci/clj-yield, which makes this trivial. This looks really nice, Jeff. Thanks. Exactly what I was looking for. I notice that the garbage-monitor deftype yields a classname error in IBM Java6.

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/5 Kyle Schaffrick k...@raidi.us On Thu, 5 Aug 2010 16:05:07 +0200 Laurent PETIT laurent.pe...@gmail.com wrote: My point was that by providing different interfaces/protocols to different users, it's more an implementation detail than anything else if they have the same object or

Re: existing idiom for delaying a future ?

2010-08-05 Thread Kyle Schaffrick
On Fri, 6 Aug 2010 00:04:08 +0200 Laurent PETIT laurent.pe...@gmail.com wrote: No offense, but ... are you serious ? So my off-the-cuff, wrote-it-in-5 minutes code is laughable? If you mean no offense then why say this at all? :( I still prefer my own version, repeated here for the record

Re: existing idiom for delaying a future ?

2010-08-05 Thread Laurent PETIT
2010/8/6 Kyle Schaffrick k...@raidi.us On Fri, 6 Aug 2010 00:04:08 +0200 Laurent PETIT laurent.pe...@gmail.com wrote: No offense, but ... are you serious ? So my off-the-cuff, wrote-it-in-5 minutes code is laughable? If you mean no offense then why say this at all? I regret having

Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]

2010-08-05 Thread Dave
Thanks Nikita, I really appreciate your help. -Dave On Aug 5, 5:53 pm, Nikita Beloglazov nikelandj...@gmail.com wrote: See my variant of your application:https://gist.github.com/efdb66487e899446332f I don't know if it works, because I can't test :( My thoughts about your example You