Plaster
New
List
Login
common-lisp
default
anonymous
2022.09.08 19:17:39
(in-package :cl-user) (define-method-combination test-standard () ((around (:around *)) ; <-- here (before (:before)) (primary () :required t) (after (:after))) (flet ((call-methods (methods) (mapcar #'(lambda (method) `(call-method ,method)) methods))) (let ((form (if (or before after (rest primary)) `(multiple-value-prog1 (progn ,@(call-methods before) (call-method ,(first primary) ,(rest primary))) ,@(call-methods (reverse after))) `(call-method ,(first primary))))) (if around `(call-method ,(first around) (,@(rest around) (make-method ,form))) form)))) (defgeneric test-gf (foo bar) (:method-combination test-standard)) (defmethod test-gf (foo bar) "This is a primary") (defmethod test-gf :around :me (foo bar) (format nil "~A (with around)" (call-next-method))) ;; CCL CL-USER> (test-gf 13 42) => "This is a primary (with around)" ;; SBCL CL-USER> (test-gf 13 42) invalid method error for #<STANDARD-METHOD COMMON-LISP-USER::TEST-GF :AROUND :ME (T T) {1003DC7BA3}> method: is applicable, but does not belong to any method group [Condition of type SIMPLE-ERROR]
Raw
Annotate
Repaste
Edit
Annotations
common-lisp
default
anonymous
2022.09.08 19:23:48
(define-method-combination test-standard () ((around (:around . *)) ; <-- here (before (:before)) (primary () :required t) (after (:after))) (flet ((call-methods (methods) (mapcar #'(lambda (method) `(call-method ,method)) methods))) (let ((form (if (or before after (rest primary)) `(multiple-value-prog1 (progn ,@(call-methods before) (call-method ,(first primary) ,(rest primary))) ,@(call-methods (reverse after))) `(call-method ,(first primary))))) (if around `(call-method ,(first around) (,@(rest around) (make-method ,form))) form))))
Raw
Repaste
Edit