stz parameter specialisation
One of the cool features of the maybe pattern is how some values have a 'not instantiated' state by default - such as pointers. A memory-address of 0 can mean 'there is no pointer' while any other value means there is a pointer.
The default maybe for things that don't have a neat 'none' state is: (value: object-class, instantiated: bool,)
. For memory addresses we don't need that extra variable, it can be just (value: (memory-address of: object-class)
.
We can specify the kind of maybe we want now that we have parameters on classes (and traits): maybe of: (memory-address of: c-string)
or maybe of: string
.
But how do we implement a specialisation so that we can take advantage of the memory savings. Let's start with the generic case first:
maybe = { class | parameters: (of: object-t,) }
If we make a new kind of maybe it'd have a new kind of name. Such as maybe-memory-address. That's not the worst solution but it'd be nice if we could write maybe of: memory-address ...
and not have to know how it's doing its magic.
The advantage of giving it a new name is we don't have as many of: calls, for instance: maybe-memory-address of: string
. So perhaps giving it a new name is a-okay.
What a weird coincidink. We already have a name for exactly this class. It's called reference. We've side stepped the need to implement specialisation. Is that always going to be the case?
reference = { class |
parameters: (of: object-t,),
variables: (address: (memory-address of: of),) }
private
[ ref instansiated? | reference -> bool | address location > 0 ]
I suppose we're going to find out the hard way eventually...