Home

MAKEINSTANCE

MAKEINSTANCE, usually written as make-instance in Common Lisp, is the standard function in the Common Lisp Object System (CLOS) used to create a new instance of a defined class. It performs the allocation of a new object and triggers the initialization machinery to set up the object's slots and state. The primary argument is the class name or class object, followed by optional keyword arguments that specify initial values for slots.

The keyword arguments to make-instance correspond to the slot names of the class (or inherited slots). For

During creation, make-instance delegates to the initialize-instance generic function. By default, a simple initialization occurs, but

In practice, make-instance forms the backbone of object creation in CLOS, enabling extensibility through the method

Example:

(defclass person ((name :initarg :name :initform "Unknown")

(age :initarg :age :initform 0)))

(make-instance 'person :name "Alice" :age 30)

See also: initialize-instance, defclass, defmethod, slot definitions.

example,
(make-instance
'person
:name
"Alice"
:age
30)
creates
a
new
person
object
with
the
name
slot
set
to
"Alice"
and
the
age
slot
set
to
30.
If
a
slot
has
a
specified
:initform
in
its
class
definition
and
no
corresponding
initarg
is
provided,
its
default
value
is
used.
If
an
initarg
is
provided,
the
value
is
assigned
accordingly
during
initialization.
users
can
define
methods
on
initialize-instance
to
customize
initial
behavior,
validate
values,
or
perform
computations.
The
typical
initialization
sequence
may
involve
run-time
checks,
derived-value
calculations,
or
side
effects,
executed
before
or
after
slots
are
set
depending
on
method
combination
and
:after
/
:before
qualifiers.
system.
It
separates
allocation
from
initialization,
allowing
developers
to
customize
how
objects
are
prepared
without
altering
the
basic
construction
mechanism.