0

In tutorials such as this one, one can simply use:

CL-USER> (class-precedence-list (find-class (class-name (class-of 123))))

In LispWorks they're available via your default package-use-list, in Allegro they're exported from ACLMOP.

But, how to use class-precedence-listand class-direct-superclasses in SBCL?

Obs.: There is a new version of this tutorial on CLOS via the The Common Lisp Cookbook.

Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
  • 2
    `class-direct-superclasses` is part of the metaobject protocol (MOP) for CLOS, which is not standardised & hence may vary among implementations. A good starting point is [Closer to MOP](https://github.com/pcostanza/closer-mop) which builds a pretty standard MOP on top of the various implementations. It's in Quicklisp. – ignis volens Mar 08 '22 at 09:06
  • 1
    I'd love if you linked to the more recent Cookbook on Github. – Ehvince Mar 09 '22 at 11:20
  • @Ehvince, it has been added :). I will read the newer version, I am just reading the older material first. – Pedro Delfino Mar 09 '22 at 20:21

1 Answers1

0

In SBCL, it is necessary to use package notation importing the symbol from sb-mop:

CL-USER> (sb-mop:class-direct-superclasses (find-class (class-name (class-of 123))))
(#<BUILT-IN-CLASS COMMON-LISP:INTEGER>)

CL-USER> (sb-mop:class-precedence-list (find-class (class-name (class-of 123))))
(#<BUILT-IN-CLASS COMMON-LISP:FIXNUM> #<BUILT-IN-CLASS COMMON-LISP:INTEGER>
 #<BUILT-IN-CLASS COMMON-LISP:RATIONAL> #<BUILT-IN-CLASS COMMON-LISP:REAL>
 #<BUILT-IN-CLASS COMMON-LISP:NUMBER> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>)
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30