[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] possible lazy-let macro?
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] possible lazy-let macro? |
Date: |
Wed, 16 Nov 2005 15:06:17 -0000 |
User-agent: |
Opera M2/8.02 (MacPPC, build 2148) |
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
- [Chicken-users] possible lazy-let macro?, Daishi Kato, 2005/11/16
- Re: [Chicken-users] possible lazy-let macro?,
Thomas Chust <=
- Re: [Chicken-users] possible lazy-let macro?, Alex Shinn, 2005/11/16
- Re: [Chicken-users] possible lazy-let macro?, Daishi Kato, 2005/11/17
- Re: [Chicken-users] possible lazy-let macro?, Thomas Chust, 2005/11/17
- Re: [Chicken-users] possible lazy-let macro?, Daishi Kato, 2005/11/17
- Re: [Chicken-users] possible lazy-let macro?, Thomas Chust, 2005/11/17
- Re: [Chicken-users] possible lazy-let macro?, Alex Shinn, 2005/11/17
- Re: [Chicken-users] possible lazy-let macro?, Daishi Kato, 2005/11/17