[plt-scheme] Space/time behaviour of Lazy Scheme
On Oct 16, jerzy.karczmarczuk at info.unicaen.fr wrote:
> Eli Barzilay kindly answers my question about lazy Scheme :
>
> >> There is nothing wrong with that. Of course, the lazy module is
> >> not exactly the same as the lazy semantics in Haskell or in
> >> Clean,
> >
> > What differences do you see?
>
> You answered yourself. There is no immediate replacement of the
> thunk (promise) by the result in *all* circumstances.
Ah, well that's a(n intentional) difference in the repl's behavior.
The language itself should be just as lazy as Haskell is.
> But this wasn't my grief, although the question about the space/time
> complexity of the system remains an interesting question. I accept,
> of course what you say here, and your comment about bangBang.
Actually, I did try things differently than you, and I do see the
problem now. FWIW -- I see the problem if I use (car (cddddr integs)),
but not if I use (fourth integs). I'll look into it.
> > So my guess is that the printout can be very consuming -- and
> > perhaps there is some problem when the nesting becomes too deep?
> > (In any case, this is not a problem of the lazy language...)
(That guess is wrong, in case it wasn't clear, but it might still be
related to how promises are printed.)
> Eli, I am not "accusing" the semantics of the language of
> anything. I just want to know what happens. Sorry, but your 'take'
> answer is not sufficient, your take is also lazy. If you *don't*
> evaluate caddr or whatever of integs, execute (take 10 integs), an
> then ask: integs, you'll get
>
> (0 . #<promise:?>)
Let me clarify -- in my course version of Lazy Scheme, all repl
results are forced with `!!'. That's why `take' is needed, because
without it typing `integs' gets into an infinite loop when trying to
print it (actually when trying to force it into a proper list). So
the interaction I was referring to was just that -- `take' with an
explicit `!!' (to mimic the imlicit one in the course version). If
you do that:
(!! (take 5 integs))
and then evaluate `integs' (without a `!!'), you'll see the
nested-forced value. It's only the car+cdddr combination that causes
problems. (Actually, even `(car (cdr integs))' seems to suffer from
the same problem.)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!