diff options
author | Matthias Benkard <code@mail.matthias.benkard.de> | 2008-03-21 19:44:09 +0100 |
---|---|---|
committer | Matthias Benkard <code@mail.matthias.benkard.de> | 2008-03-21 19:44:09 +0100 |
commit | d66cb037db9c42d42528bfcf6fdf18ecbb94499f (patch) | |
tree | a32988043db7e0d660b2b5f12dc3546c6b2590c5 | |
parent | 8d18782f12e2316ce4f66a7a25ebe8f70eb97522 (diff) |
Explain the rationale for passing a static class name as the first argument to every OBJECTIVE-C-GENERIC-FUNCTION.
darcs-hash:e1afc0fc7530051417435a68b13a4cab52e4a893
-rw-r--r-- | Lisp/method-definition.lisp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lisp/method-definition.lisp b/Lisp/method-definition.lisp index caedec9..a000c49 100644 --- a/Lisp/method-definition.lisp +++ b/Lisp/method-definition.lisp @@ -71,6 +71,37 @@ undefined.")) `(define-objective-c-method ,name ,@args)) +;; Put simply, a DEFINE-OBJECTIVE-C-METHOD form is transformed into a +;; DEFMETHOD form along with the code needed for initialisation of the +;; corresponding Objective-C method and registration of the callback. +;; +;; Note that mapping Objective-C methods to generic functions in a naive +;; way breaks super calls, because the following can (and will) happen: +;; +;; 1. Someone sends a message to a Lisp-based instance. +;; +;; 2. The callback is entered. It calls the generic function of the +;; same name, which invokes the effective method applying to the +;; object and method arguments. +;; +;; 2. The method calls super. +;; +;; 3. The callback for the parent class is entered. It, in turn, calls +;; the generic function of the same name, which invokes the same +;; effective method called in step 1. Oops. +;; +;; There are two solutions to this problem: +;; +;; 1. Do not use generic functions and methods at all, but define a +;; function for each callback. +;; +;; 2. Pass the class name as the first argument so that the dispatch +;; mechanism may dispatch over it. +;; +;; Option (2), which is what we do, is preferable because it allows the +;; user to dispatch over an arbitrary set of arguments other than the +;; first by reusing the standard CLOS generic function dispatch +;; mechanism. (defmacro define-objective-c-method (name &rest args) "Define a new Objective-C method. |