Allocators - Spicery/Nutmeg GitHub Wiki

In a nutshell, allocators are procedures that return store, including mutable store, but do not mutate any pre-existing store nor performa any external I/O. In Nutmeg's terms, they are sideeffectfree and only accept const input arguments. Their significance to the compiler is that any store that is returned is guaranteed to be either const or unshared. This enables the compiler to eliminate superfluous copying when it knows that it has the only copy.

Allocators can be marked using the @allocator annotation, which is equivalent to the two annotations @leakproof @const(in).

Example

@allocator
def pairOfRefs( const x, const y ):
    tuple( ref( x ), ref( y ) )
end

No Obligation

Procedures marked as @allocator are not absolutely obliged to allocate new store, although that's likely to be a bit confusing. If it's not allocating store it can almost certainly be marked as a @finesse, which is a bit more helpful to the reader.

@allocator 
def reallyAFunction( const x ):
     x
end