[CM] __func__ in lisp?

Kjetil S. Matheussen k.s.matheussen at notam02.no
Thu Jul 23 07:49:36 PDT 2009



On Thu, 23 Jul 2009, Bill Schottstaedt wrote:

> I've googled around and looked through clTl2 but I can't find a way
> in Lisp (scheme) to get the current function name (from an embedded
> macro, for example).  Is there some (non-)standard way to do this?
>

At least in Guile, you can redefine 'define'.
So using a global variable to store the last called
function should work. Untested:

(define last-called-function #f)

(define old-define define)

(define-macro (define def . code)
   (if (pair? def)
       (let ((name (car def)))
         (set! code `((lambda ,(cdr def)
                        (set! last-called-function ',name)
                        (let ()
                          , at code))))
         (set! def name)))
   `(old-define ,def
                (let ();
                  (set! last-called-function ',name)
                  (let ()
                    , at code))))



More information about the Cmdist mailing list