Reputation: 19
Can you help me? I don't understand this code's part
(lambda (this &rest args) ;; Adds The THIS Argument
(apply (get-slot this
method-name)
(append (list this)
args))))
Rewrite Method
;;;; This Function Add The Argument This To The Method
(defun rewrite-method (method-spec)
(list 'lambda (append (list 'this) ;; Add The THIS Argument
(second method-spec))
(cons 'progn (rest (rest method-spec))))) ;; Eval All The Method's Body
;;;; Method-Process
;;;; Function Used To Process Methods, Rewriting Them To
;;;; Lisp Functions
(defun method-process (method-name method-spec)
(setf (fdefinition method-name) ;; Associate The Lambda To The Method's Name
(lambda (this &rest args) ;; Adds The THIS Argument
(apply (get-slot this
method-name)
(append (list this)
args))))
(eval (rewrite-method method-spec))) ;; Returned Value
Upvotes: 1
Views: 100
Reputation: 139261
It takes an arglist (foo bar baz)
and adds a this
parameter: (this foo bar baz)
.
Thus a function (lambda (foo bar baz) ...)
then is (lambda (this foo bar baz) ...)
.
This is useful in implementation of single-inheritance object-oriented languages where the first argument is the object which receives a message and other arguments. Here the parameter this
is the receiving object.
Note that the call to APPLY
could be improved. (apply function (append (list this) args))
is just (apply function this args)
.
Upvotes: 3