New vs instantiate vs make-object

6.3 Creating Objects shows three separate methods for creating objects:

(make-object class init-v ...) → object?
(new class-expr (id by-name-expr) ...)
(instantiate class-expr (by-pos-expr ...) (id by-name-expr) ...)

If I'm reading this right, there are three differences between these methods:

A) make-object uses all positional initialization, new uses all named initialization, and instantiate allows you to mix the two styles
B) make-object is a procedure, the other two are syntactic forms
C) make-object takes a class as its first argument while the other two take class expressions.

This leaves me with some questions:

  1. Are there other differences?
  2. Should I prefer one approach over another?
  3. What is the difference between a 'class' and a 'class expression' in this context? My understanding is that when an expression is validated the system works from the inside out, so by the time make-object or new are being evaluated there should be a class value sitting in that first slot.

In regular code I tend to prefer keywords for anything that has more than 2-3 arguments, so I instinctively lean away from make-object but maybe there's a reason not to.

1 Like

The difference between "class" and "class expression" is just about function vs macro. You can put an expression that evaluates to a class as the first argument to make-object because function application takes arbitrary expressions.

In general, you should use new and named init arguments, everything else is legacy.

5 Likes

Brilliant. Thanks, Sam.