[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Lexical environment of method
Date: Mon, 12 Mar 90 19:18:18 -0500
From: kanderso@DINO.BBN.COM
I am confused by your example, but if you want a lexical function
that references the instance variables of an instance, you just have
the instance create the closure:
(defflavor widget
((fn)
(ivar "puzzle"))
())
(defmethod (setup-fn widget) ()
(setf fn #'(lambda () ... what you want done...)))
(defmethod (use-fn widget) ()
... (funcall fn) ...)
This is completely correct.
If you really want top level defun-in-flavor, like:
(defun-in-flavor (fun widget) ()
...)
then you can try:
(defmethod (setup-fn widget) ()
(setf fn #'(defun-in-flavor fun widget)))
In the lexical environment inside the method body, #'FUN is exactly equivalent to
#'(DEFUN-IN-FLAVOR FUN WIDGET), except you don't have to go through this
nonsense:
(defmethod (use-fn widget) ()
... (funcall fn self sys:self-mapping-table) ...)
You can just say (FUNCALL FN), or, better yet, (FUNCALL (WIDGET-FN WIDGET)).
That's because #'FUN is actually a lexical closure of
#'(lambda (&rest args)
(apply #'(defun-in-flavor fun widget) self self-mapping-table args))
which is what you want almost all the time. For example, you can pass #'FUN to
things like MAP and PROCESS-WAIT, which you could not do with your FN above.)
[It should set your hackles on end when you see internal things like
SELF-MAPPING-TABLE and #'(DEFUN-IN-FLAVOR ...) in your code.]