chicken-users
[Top][All Lists]
Advanced

[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: Thu, 17 Nov 2005 07:40:27 +0900
User-agent: Wanderlust/2.15.1 (Almost Unreal) Emacs/21.4 Mule/5.0 (SAKAKI)

Hi,

I have first considered the use of delay/force,
but it turns out that it is a little bit costly.
So, I want it to be done at the complie time.
This should probablly be called let-ahead instead of lazy-let.
Anyway, your macro example is helpful to me.
Let me think again.

Thanks,
Daishi

At Wed, 16 Nov 2005 15:06:17 -0000,
Thomas Chust wrote:
> 
> Am 16.11.2005, 09:18 Uhr, schrieb Daishi Kato <address@hidden>:
> 
> > [...]
> > Does anyone know of any existence of a lazy-let macro,
> > which does the following?
> >
> > <convert from>
> >
> > (lazy-let ([a (get-a)][b (get-b)])
> >   (if (condition) a b))
> >
> > <into>
> >
> > (if (condition) (get-a) (get-b))
> > [...]
> 
> Hello,
> 
> I haven't seen any macro like this, yet. As a workaround, I would
> maybe use promises like this (transformation of the above example)
>    (let ((a (delay (get-a))) (b (delay (get-b))))
>      (if (condition) (force a) (force b)))
> 
> Of course this could fairly easily be automated using a non-hygienic
> macro:
>    (use match)
> 
>    (define-macro (lazy-let vars . body)
>      `(let ,(map (match-lambda ((var xpr) `(,var (delay ,xpr)))) vars)
>         ,@(map
>             (let ((names (map car vars)))
>               (rec (auto-force xpr)
>                 (cond
>                  ((list? xpr)
>                   (map auto-force xpr))
>                  ((and (symbol? xpr) (memq xpr names))
>                   `(force ,xpr))
>                  (else
>                   xpr))))
>             body)))
> 
> But it has the disadvantage, that you cannot transparently use set!
> on the variables you declare with this form.
> 
> cu,
> Thomas





reply via email to

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