Re: what flet doesn't work here??
- From: Ron Garret <rNOSPAMon@xxxxxxxxxxx>
- Date: Sat, 23 Dec 2006 18:29:38 -0800
In article <96OdnekPAoaQSRDYnZ2dnUVZ_sOknZ2d@xxxxxxxxxxxxx>,
rpw3@xxxxxxxx (Rob Warnock) wrote:
Ron Garret <rNOSPAMon@xxxxxxxxxxx> wrote:
+---------------
| The wonderful thing about CL is that it imposes very few constraints
| that cannot be dispensed with in a few lines of code:
|
| (defmacro ddefun (fname args &body body) ...)
+---------------
Yes, but as I pointed out upthread, that only works if you use
DDEFUN to define *all* the functions you want to be able to later
use DFLET with. I got the impression the OP wanted to be able to
override functions already defined by other code [though I could
be mistaken], which your certainly nice macros can't help with.
[AFAIK, nothing can, in general.]
Piffle.
(defmacro dflet (bindings &body body)
(loop for (fname . ignore) in bindings do
(unless (member fname *dynamically-bound-functions*)
(push fname *dynamically-bound-functions*)
(eval `(progn
(defvar ,fname)
(setf ,fname ,(and (fboundp fname) `#',fname))
(defun ,fname (&rest args) (apply ,fname args))))))
`(let ,(mapcar (lambda (b) `(,(car b) (lambda ,(second b) ,@(cddr b))))
bindings)
,@body))
? (defvar *DYNAMICALLY-BOUND-FUNCTIONS* '())
*DYNAMICALLY-BOUND-FUNCTIONS*
? (defun f1 () 'f1)
F1
? (defun f2 () (f1))
F2
? (dflet ((f1 () 'foo)) (f2))
FOO
? (f2)
F1
?
rg
.
- Follow-Ups:
- Re: what flet doesn't work here??
- From: Pascal Costanza
- Re: what flet doesn't work here??
- References:
- what flet doesn't work here??
- From: sailormoontw@xxxxxxxxx
- Re: what flet doesn't work here??
- From: sailormoontw@xxxxxxxxx
- Re: what flet doesn't work here??
- From: Michal Krupka
- Re: what flet doesn't work here??
- From: Ron Garret
- Re: what flet doesn't work here??
- From: Rob Warnock
- what flet doesn't work here??
- Prev by Date: Re: what flet doesn't work here??
- Next by Date: Re: merits of Lisp vs Python
- Previous by thread: Re: what flet doesn't work here??
- Next by thread: Re: what flet doesn't work here??
- Index(es):
Relevant Pages
|