[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 08:18:11 +0900
User-agent: Wanderlust/2.15.1 (Almost Unreal) Emacs/21.4 Mule/5.0 (SAKAKI)


Thanks for many examples!

At Thu, 17 Nov 2005 17:31:06 -0000,
Thomas Chust wrote:
> For example
>    (lazy-let ((a (get-a)))
>      (let ((a (get-something-else)))
>        (if (condition) a #f)))
> always evaluates (get-a) even though it is never needed, because it
> macroexpands into
>    (begin
>      (let ((a (get-a)))
>        (let ((a (get-something-else)))
>          (if (condition) a #f))))

This one is OK for me, it just did nothing.

> A more academic example can also generate invalid code:
>    (lazy-let ((a (get-a)))
>      (let ((a (get-something-else)))
>        (do-something-unrelated)))
> transforms into
>    (begin
>      (let (((get-a) (get-something-else)))
>        (do-something-unrelated)))

Oh, this is a big problem. I didn't know that.
I have expected such a limitation.

> The same type of problem also occurs with this kind of expression:
>    (lazy-let ((a (get-a)))
>      (if (condition) a 'a))
> transforming into
>    (begin
>      (let ((a (get-a)))
>        (if (condition) a 'a)))

Yes, you are right. It also occurs with "a".

> where we have evaluation in unnecessary cases again. Or even worse
> with another academic example:
>    (lazy-let ((a (get-a)))
>      'a)
> transforming into
>    (begin
>      '(get-a))

Ah, how bad.

Another counter example could be made by combining with
other macros that do some dynamic code creation.

> I cannot think of an easy way to fix this without having to make the
> macro quite syntax-aware, though. Therefore I would rather suggest to
> implement the whole thing for regular let forms in one of the compiler's
> optimization passes ;)

I first thought this was an optimization issue in the complier,
but it might be not, because in some case there is a side effect,
while assigning let variables.  If it is possible for the compiler
to optimize with the normal let, I would prefer it.

Would it be worth improving the lazy-let macro
so that it understands at least let and quote forms?


reply via email to

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