[Top][All Lists]

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

Re: [Chicken-users] possible lazy-let macro?

From: Daishi Kato
Subject: Re: [Chicken-users] possible lazy-let macro?
Date: Fri, 18 Nov 2005 13:09:31 +0900
User-agent: Wanderlust/2.15.1 (Almost Unreal) Emacs/21.4 Mule/5.0 (SAKAKI)

Thanks, Tohmas and Alex!

I think I understand that simple code-walking does not help,
in many cases, for example, a loop.

  (lazy-let ((a (get-a)))
    (letrec ([b (lambda () (when (condition) (print a) (b)))])

OK, I would not need a general solution,
let me think about it for a while.

Thanks for comments, and any more comments are welcome.

At Thu, 17 Nov 2005 19:19:46 -0600,
Alex Shinn wrote:
> At Fri, 18 Nov 2005 08:18:11 +0900, Daishi Kato wrote:
> > 
> > Would it be worth improving the lazy-let macro
> > so that it understands at least let and quote forms?
> Not let forms.  Analyzing subforms of a macro is called code-walking,
> and the first thing you then need to do is sc-expand the body or
> lazy-let won't play well with other macros.  At that point there are
> no let's remaining, and everything is in terms of lambda.
> But I think the problem you're trying to solve is in general
> unsolvable.  Consider the form:
>   (lazy-let ((a (get-a)))
>     (list (if (condition-1) a #f)
>           (if (condition-2) a #f)))
> If you expand this to
>   (list (if (condition-1) (get-a) #f)
>         (if (condition-2) (get-a) #f))
> then you may end up calling get-a twice.  However, if you compute the
> value once outside the nearest enclosing form for all occurances:
>   (let ((a (get-a)))
>     (list (if (condition-1) a #f)
>           (if (condition-2) a #f)))
> then you always compute get-a even when it may not be needed.
> -- 
> Alex

reply via email to

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