Re: [racket-users] out of memory with streams

2019-03-12 Thread bedeke

On Tuesday, 12 March 2019 19:21:12 UTC+1, Ben Greenman wrote:
>
> You can also use sequences: 
>
> #lang racket/base 
> (require racket/sequence) 
>
> (sequence-ref (in-producer (let ([i 0]) (lambda () (begin0 i (set! i 
> (+ i 1)) 
>   2000) 
> (sequence-ref (in-naturals) 
>   2000) 
>

Thank you.

The actual sequence was building a list for each element.
I had a recursive algorithm to produce this. But the total list was 
definitely too big. So I was hoping that by turning it into a stream I 
could avoid keeping every element in memory.
In the end I used a generator and modified the algorithm to track state...

KR.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] out of memory with streams

2019-03-12 Thread Ben Greenman
You can also use sequences:

#lang racket/base
(require racket/sequence)

(sequence-ref (in-producer (let ([i 0]) (lambda () (begin0 i (set! i
(+ i 1))
  2000)
(sequence-ref (in-naturals)
  2000)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] out of memory with streams

2019-03-12 Thread bedeke


On Tuesday, 12 March 2019 16:06:59 UTC+1, Matthias Felleisen wrote:
>
>
>
> > On Mar 12, 2019, at 10:48 AM, bedeke > 
> wrote: 
> > 
> > 
> > Sorry for not being clear. 
> > I knew that increasing the memory limit could make this run without 
> problems since the data in each cell of the stream is so small. 
> > I was running this example with a memory limit of 128MB. 
> > I made my own quick stream implementation, and this runs the above 
> example with the low memory limit without problems and without noticeable 
> GC happening. At the cost of having to reevaluate every stream from the 
> beginning. 
> > I was just curious if there was a stream implementation that avoids 
> memoization. 
>
>
> The very notion of ‘stream’ implies memoization. What I am surprised about 
> is that racket/stream (unlike #lang lazy) does not memoize exceptions, 
> which is even more expensive — Matthias 
>
>
Ok,

thank you. Then I will search in a different direction.
I wanted to avoid generators, but it looks like this will be the better 
option.

B.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] out of memory with streams

2019-03-12 Thread Matthias Felleisen



> On Mar 12, 2019, at 10:48 AM, bedeke  wrote:
> 
> 
> Sorry for not being clear.
> I knew that increasing the memory limit could make this run without problems 
> since the data in each cell of the stream is so small.
> I was running this example with a memory limit of 128MB.
> I made my own quick stream implementation, and this runs the above example 
> with the low memory limit without problems and without noticeable GC 
> happening. At the cost of having to reevaluate every stream from the 
> beginning.
> I was just curious if there was a stream implementation that avoids 
> memoization.


The very notion of ‘stream’ implies memoization. What I am surprised about is 
that racket/stream (unlike #lang lazy) does not memoize exceptions, which is 
even more expensive — Matthias

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] out of memory with streams

2019-03-12 Thread bedeke


On Tuesday, 12 March 2019 14:50:38 UTC+1, Matthias Felleisen wrote:
>
>
>
> On Mar 12, 2019, at 3:10 AM, bedeke > 
> wrote:
>
> Hello,
>
> when running any of the following the program runs out of memory:
>
> #lang racket/base
> (require racket/stream)
>
> (stream-ref (let ([i 0])(stream-cons i (let 
> loop ()(set! i (+ i 1))(stream-cons i (loop)
> 2000)
> (stream-ref (for/stream ([i (in-naturals)]) i)
>   2000)
>
> I guess this is because of memoization, but I was hoping that since I 
> don't keep a reference to the first element of the stream, it would be 
> discarded. This doesn't seem to be happening.
> Is there a way to disable memoization for streams? Or is there an other 
> issue?
>
> (the actual stream I want to build/traverse without keeping it in memory 
> is at http://pasterack.org/pastes/63574)
>
>  
>
> I ran this program: 
>
> #lang racket/base
>
> (require racket/stream)
> (stream-ref (let ([i 0]) (stream-cons i (let loop () (set! i (+ i 1)) 
> (stream-cons i (loop) 2000)
>
> ;; please write this: the above is Fortran in Racket 
> (stream-ref (let loop ([i 0]) (stream-cons i (loop (+ i 1 2000)
>
>
> I got (with serious GC happening between the two results): 
>
> Welcome to DrRacket, version 7.2.0.6--2018-05-23(-/f) [3m].
> Language: racket/base, with debugging; memory limit: 2048 MB.
> 2000
> 2000
>
>
>
Sorry for not being clear.
I knew that increasing the memory limit could make this run without 
problems since the data in each cell of the stream is so small.
I was running this example with a memory limit of 128MB.
I made my own quick stream implementation, and this runs the above example 
with the low memory limit without problems and without noticeable GC 
happening. At the cost of having to reevaluate every stream from the 
beginning.
I was just curious if there was a stream implementation that avoids 
memoization.

KR,
Bert


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] out of memory with streams

2019-03-12 Thread Matthias Felleisen


> On Mar 12, 2019, at 3:10 AM, bedeke  wrote:
> 
> Hello,
> 
> when running any of the following the program runs out of memory:
> 
> #lang racket/base
> (require racket/stream)
> 
> (stream-ref (let ([i 0])(stream-cons i (let loop ()(set! i (+ i 
> 1))(stream-cons i (loop)
> 2000)
> (stream-ref (for/stream ([i (in-naturals)]) i)
>   2000)
> 
> I guess this is because of memoization, but I was hoping that since I don't 
> keep a reference to the first element of the stream, it would be discarded. 
> This doesn't seem to be happening.
> Is there a way to disable memoization for streams? Or is there an other issue?
> 
> (the actual stream I want to build/traverse without keeping it in memory is 
> at http://pasterack.org/pastes/63574)
 

I ran this program: 

#lang racket/base

(require racket/stream)
(stream-ref (let ([i 0]) (stream-cons i (let loop () (set! i (+ i 1)) 
(stream-cons i (loop) 2000)

;; please write this: the above is Fortran in Racket 
(stream-ref (let loop ([i 0]) (stream-cons i (loop (+ i 1 2000)


I got (with serious GC happening between the two results): 

Welcome to DrRacket, version 7.2.0.6--2018-05-23(-/f) [3m].
Language: racket/base, with debugging; memory limit: 2048 MB.
2000
2000


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] out of memory with streams

2019-03-12 Thread bedeke
Hello,

when running any of the following the program runs out of memory:

#lang racket/base
(require racket/stream)

(stream-ref (let ([i 0])(stream-cons i (let loop ()(set! i (+ i 1))(stream-cons 
i (loop)
2000)
(stream-ref (for/stream ([i (in-naturals)]) i)
  2000)

I guess this is because of memoization, but I was hoping that since I don't 
keep a reference to the first element of the stream, it would be discarded. 
This doesn't seem to be happening.
Is there a way to disable memoization for streams? Or is there an other 
issue?

(the actual stream I want to build/traverse without keeping it in memory is 
at http://pasterack.org/pastes/63574)

Kind regards,
Bert

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.