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)
)?