[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lexical environment of method

I don't think you can do precisely what you're trying to do.  Maybe you
should use symbol-value-in-instance to do what you want.

The defun-in-flavor method could work, though.  You could write it as

(let* ((internal-function-form
	 `(defun-in-flavor (,(gensym) widget) (string)
	    (format t "~%~a ~a" string ivar)))
       (internal-function-name (compile (eval internal-function-form)))
       (internal-function (fdefinition internal-function-name)))
  (setq foo (make-instance 'widget :fn internal-function)))

Note the use of the gensym'ed name to solve the problem you mentioned of
using duplicate function names.  With some appropriate macrology you could
get rid of the EVAL, but then you might get complaints at compile time
about non-top-level DEFUN-IN-FLAVORs.