Skip to content

Instantly share code, notes, and snippets.

@scymtym
Created December 23, 2021 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scymtym/c4b842f04fe37ef52745d3ed3ea97e50 to your computer and use it in GitHub Desktop.
Save scymtym/c4b842f04fe37ef52745d3ed3ea97e50 to your computer and use it in GitHub Desktop.
Traits
(cl:in-package #:language-extension.protocol.dispatch)
;;;
(defgeneric test (x))
(p:defprotocol (role) specializer-test ()
(:initarg :foo role)
(:method test ((x role))))
(defclass test-class-2 () ())
(defmethod test ((x test-class-2))
:working)
(defclass test-class (test-class-2)
((%x :initarg :foo)))
(defclass unrelated () ())
(defgeneric test-2 (x y)
(:generic-function-class protocol-generic-function))
(defmethod test-2 ((x (protocol-role role specializer-test)) (y fixnum))
(test x))
#+later (test-2 (make-instance 'test-class))
(specializer-test-role-p 1)
(specializer-test-role-p (c2mop:class-prototype (c2mop:ensure-finalized (find-class 'test-class))))
(specializer-test-role-p (c2mop:class-prototype (c2mop:ensure-finalized (find-class 'test-class-2))))
(test-2 (make-instance 'unrelated))
(typep 1 '(protocol-role role specializer-test))
(typep (c2mop:class-prototype (find-class 'test-class)) '(protocol-role role specializer-test))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment