Re: what flet doesn't work here??

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.]


(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))))

? (defun f1 () 'f1)
? (defun f2 () (f1))
? (dflet ((f1 () 'foo)) (f2))
? (f2)


Relevant Pages

  • Re: what flet doesnt work here??
    ... rpw3@xxxxxxxx (Rob Warnock) wrote: ... (defmacro dflet (bindings &body body) ...
  • Re: Binding in defparameter versus let
    ... The binding for let doesn't occur until running, so (third bar) is unbound. ... In Scheme you could do what you want using LETREC, but Common Lisp ... (defmacro letrec ((&rest bindings) ...
  • Re: Let Over Lambda chapter 4
    ... (defmacro dynamic-let (bindings &body body) ... (destructuring-bind (var form) ...
  • Thread-safe closures
    ... (defmacro with-threadsafe-binding ((var default) ... (defmacro thread-let ((&rest bindings) ...
  • Re: what flet doesnt work here??
    ... but what I want is replacing the current definition of a ... (defmacro ddefun (fname args &body body) ... (defmacro dflet (bindings &body body) ...