1

When an EIEIO class is defined:

(defclass my-test ()
  ((slot1 :initform 0)))

A constructor function of the same name is also defined. However, there's also make-instance, which also makes a new instance of the class.

(let ((a (make-instance 'my-test)) ; -> #s(my-test 0)
      (b (my-test))) ; -> #s(my-test 0)
  (equal a b))
;; -> t

I see that they are different in at least one way: the contructor function prevents one from making an instance of an abstract class, whereas make-instance will ignore it and create an instance anyways.

(defclass my-abstract ()
  ((slot1 :initform 0))
  :abstract t)

(make-instance 'my-abstract) ; -> #s(my-abstract 0)
(my-abstract) ; (error "Class my-abstract is abstract")

Given that, when should one use make-instance, and when should one use the constructor function ((my-test))?

Kisaragi Hiu
  • 315
  • 1
  • 6
  • I imagine that in almost all cases, you want to use the c'tor. The doc (`C-h i g(eieio)making new objects`) says: `To create an object from a class symbol, use ‘make-instance’.`, but that's about the only exception mentioned. – NickD Sep 08 '21 at 05:37

0 Answers0