Re: lazyness

2012-02-24 Thread Sunil S Nandihalli
Thanks Mark, I think that worked!! Sunil. On Sat, Feb 25, 2012 at 10:54 AM, Mark Rathwell wrote: > Try this (you need to wrap the return val of helper in lazy-seq also): > > (defn pair-sequences-by > ([seq-1 seq-2 f1 f2] > "s1 and s2 are guaranteed to be strictly monotonically increasing >

Re: lazyness

2012-02-24 Thread Mark Rathwell
Try this (you need to wrap the return val of helper in lazy-seq also): (defn pair-sequences-by ([seq-1 seq-2 f1 f2] "s1 and s2 are guaranteed to be strictly monotonically increasing whith respect to f1 and f2 as keys respectively. The return value is pairs of elements e1 from s1 and e2 fro

Lazyness of range (was: Re: Counting vowels, take II.)

2010-03-23 Thread Douglas Philips
On 2010 Mar 23, at 9:28 PM, Per Vognsen wrote: So you can see that scan-filter-zip is lazy in the source sequence but apparently not the primary input sequence. That was surprising to me because I see nothing in my code that should have forced that. Then I remember that some functions like range

Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Ah, brilliant, many thanks Laurent! Interesteresting stuff under the hood .. Kind regards, alux Laurent PETIT schrieb: > hi, follow links from here: > http://www.infoq.com/news/2009/12/clojure-11-rc1-transients > > chunked sequences have their first elements realized in advanced by > packets of

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
hi, follow links from here: http://www.infoq.com/news/2009/12/clojure-11-rc1-transients chunked sequences have their first elements realized in advanced by packets of 32 Under the hoods, it seems that range uses chunked sequences ( http://github.com/richhickey/clojure/blob/master/src/clj/clojure/

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
Yes, chunked sequences explain the behaviour, look: 1:1 user=> (set! *print-length* 10) 10 1:2 user=> (defn fib0 [n] (let [fib (fn fib [n] (if (< n 1) 1 (+ (fib (- n 1)) (fib (- n 2)] (println (str "fib0[" n "]")) (fib n))) #'user/fib0 1:7 user=> (time (map fib0 (iterate inc 0))) "

Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Laurent, > Could chunked seqs explain something here ? sounds possible. If I only knew what this is ;-) Regards, alux Laurent PETIT schrieb: > 2010/3/19 alux : > > ;-) > > > > Still, I dont believe. > > > > I get the same difference with > > > > user=> (time (map fib0 (range 100))) > > "Elapsed

Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Meikel, you are right, I changed horses, uh, definitions inbetween. So the REPL interaction of my last response should read Clojure 1.1.0 user=> (set! *print-length* 10) 10 user=> (defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2) #'user/fib0 user=> (time (map fib0 (range 100))) "El

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi, On Mar 19, 1:39 pm, alux wrote: > Still, I dont believe. You should... > > I get the same difference with > > user=> (time (map fib0 (range 100))) > "Elapsed time: 1.916445 msecs" > > more than 5 seconds > > (0 1 1 2 3 5 8 13 21 34 ...) > > user=> (time (map fib0 (iterate inc 0))) > "Elaps

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
2010/3/19 alux : > ;-) > > Still, I dont believe. > > I get the same difference with > > user=> (time (map fib0 (range 100))) > "Elapsed time: 1.916445 msecs" > > more than 5 seconds > > (0 1 1 2 3 5 8 13 21 34 ...) > > user=> (time (map fib0 (iterate inc 0))) > "Elapsed time: 0.104203 msecs" > (0

Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
;-) Still, I dont believe. I get the same difference with user=> (time (map fib0 (range 100))) "Elapsed time: 1.916445 msecs" more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user=> (time (map fib0 (iterate inc 0))) "Elapsed time: 0.104203 msecs" (0 1 1 2 3 5 8 13 21 34 ...) Hm. Regards, al

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi, On Mar 19, 12:34 pm, alux wrote: > You didnt try this, as I can judge, because you responded in finite > time ;-) Ah, yes. Intersperse with (take 10 ...) at will. :) > My main irritation is still: Why do my range and my iterate version > differer in their print beheavior? Because with ran

Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
You didnt try this, as I can judge, because you responded in finite time ;-) (fib0 35) takes 20 seconds already. So your suggestion (time (doall (map fib0 (range 100))) will do all up to 100, time it, and print the first ten, in that order. (fib0 100) takes a good while (I just estimaded 15 mill

Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi, On Mar 19, 11:27 am, alux wrote: > user=> (time (fib0 35)) > "Elapsed time: 20874.18345 msecs" > 24157817 > > user=> (time (map fib0 (iterate inc 1))) > "Elapsed time: 0.913524 msecs" > (2 3 5 8 13 21 34 55 89 144 ...) > > Everything fine. > Now what puzzles me: > > user=> (time (map fib0 (r

REPL behaviour / time / lazyness

2010-03-19 Thread alux
Hello, I played a bit with Fibonacci again. The slow and inefficient way ;-) (defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2) user=> (time (fib0 35)) "Elapsed time: 20874.18345 msecs" 24157817 I use (set! *print-length* 10) and tried some mapping: user=> (time (map fib0 (iterat

Re: Switching off lazyness

2009-10-02 Thread Meikel Brandmeyer
Hi, Am 03.10.2009 um 06:09 schrieb Vagif Verdi: You can do so by with doall: (doall (map ... (filter ...))) Unfortunately this is not true. Yo are paying penalty for lazyness in this case. Try it yourself. Write non lazy versions of map and filter and time them against standard ones

Re: Switching off lazyness

2009-10-02 Thread Vagif Verdi
On Oct 2, 1:37 pm, Meikel Brandmeyer wrote: > You can do so by with doall: > >      (doall (map ... (filter ...))) > Unfortunately this is not true. Yo are paying penalty for lazyness in this case. Try it yourself. Write non lazy versions of map and filter and time them agai

Re: Switching off lazyness

2009-10-02 Thread Meikel Brandmeyer
Hi, Am 02.10.2009 um 22:01 schrieb Vagif Verdi: This is not a suggestion or anything, just entertaining myself with some uneducated thinking. What if all lazy functions (map filter etc) would check some global value and decide upon it lazyness ? Then we could do something like this: (eager

Switching off lazyness

2009-10-02 Thread Vagif Verdi
This is not a suggestion or anything, just entertaining myself with some uneducated thinking. What if all lazy functions (map filter etc) would check some global value and decide upon it lazyness ? Then we could do something like this: (eager (map ...(filter ...))) That would allow to not

Re: special variables and lazyness

2008-10-09 Thread Sacha
> I'm confused - what was your expectation here? In what way is Clojure > different from CL? > > Rich Nothing is different. Sorry i wasn't very explicit. That's the way a special should work, and expecting a different behaviour for lazyness

Re: special variables and lazyness

2008-10-09 Thread Rich Hickey
On Oct 9, 2:46 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Sacha, > > You can to force evaluation of *indent* while preserving the lazyness > of the code that uses *indent*: > > (with-indent >(print *indent*) >(let [ind *indent*] > (lazy-cons

Re: special variables and lazyness

2008-10-09 Thread Rich Hickey
On Oct 9, 7:28 pm, Sacha <[EMAIL PROTECTED]> wrote: > On Oct 9, 8:46 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > > You can to force evaluation of *indent* while preserving the lazyness > > of the code that uses *indent*: > > > (with-indent > >

Re: special variables and lazyness

2008-10-09 Thread Sacha
On Oct 9, 8:46 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > You can to force evaluation of *indent* while preserving the lazyness   > of the code that uses *indent*: > > (with-indent >    (print *indent*) >    (let [ind *indent*] >      (lazy-cons ind (cons ind n

Re: special variables and lazyness

2008-10-09 Thread Stuart Halloway
Sacha, You can to force evaluation of *indent* while preserving the lazyness of the code that uses *indent*: (with-indent (print *indent*) (let [ind *indent*] (lazy-cons ind (cons ind nil If this idiom is useful often enough there could be a macro for it. Or maybe there

special variables and lazyness

2008-10-09 Thread Sacha
Here is a little test : (def *indent* 0) (defmacro with-indent [& body] `(binding [*indent* (+ *indent* 1)] [EMAIL PROTECTED])) => (with-indent (print *indent*) (lazy-cons *indent* (cons *indent* nil))) 1(0 0) I somehow expected to have the special variable value lexically bound at eval