guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior with delayed objects


From: Andy Wingo
Subject: Re: Strange behavior with delayed objects
Date: Fri, 21 May 2010 12:59:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hello,

On Fri 14 May 2010 23:53, user8472 <address@hidden> writes:

> The solution is thus to wrap the defines in (lambda () ...)s.
>
> <code>
> (define (solve f y0 dt)
>   (define (y) (integral (delay (dy)) y0 dt))
>   (define (dy) (stream-map f (y)))
>   (y))
>
> (debug-set! stack 2000000)
> (stream-ref (solve (lambda (x) x) 1 0.001) 1000)
> </code>
>
> will produce the correct answer. The downside is that the function calls
> will be wrapped recursively which necessitates increasing the stack size.
> Plus, it's much slower this way. But it works.

The fact that it's slow is an implementation detail. Lambda expressions
are simply abstractions over scope -- they do not necessitate the
creation of closures. Guile 2.0 is already much faster for this case,
I believe, and with a proper inliner, y and dy would not actually be
implemented with functions.

Andy
-- 
http://wingolog.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]