Creating Structs using MyStruct(x, y, x) vs creating an object using 'new MyObject'


Yves Cloutier
 

First off just wanted to say I was reading chapter 4.6 - Underneath the Hood" and found it pretty interesting to understand the mechanism of how Stanza decides which method/multi to apply.  Multi-file "matching". Brilliant.

Now, I was gonna ask a question asking to clarify the difference use case for creating an instance f a struct vs using objects, but as I kept reading  a bit further, 4.15 - Revisiting Defstruct clearly explained.

Following the code sample on p.77, it states:

"defstruct construct expands to: 1. A type definition; 2. getter functions; 3 setter functions...".
Is this expansion done via macros?


 

Hi Yves,

Glad that you enjoyed reading chapter 4. Proper multiple-dispatch is a feature that we knew we wanted from the very beginning.

The defstruct expansion is indeed done using Stanza's macro system. If you are curious, the gen-defstruct function in compiler/stz-core-macros.stanza contains the implementation for how defstruct is expanded. The implementation is a bit complex, but it's ultimately just a bunch of s-exp manipulation.

Patrick