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 <[EMAIL PROTECTED]>: > > > [...] > > 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 _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users