Menu

Accessing structure members and Pass-by-reference

Mark Anthony Taylor (Shyreman)

Given a structure defined as a local variable or input variable, we can access the individual
members using the period character:

(struct Vector4f (float x y z w))
...
(function ... :
    (Vector4f v = 0 0 0 1)
    (Float value = v.x) // Retrieve the x component of the structure and assign to a local variable.
    (v.y = (Sys.Maths.F32.Sin value)) // Evaluate a function and return the output to the y-component
    (Sys.Maths.F32.Cos v.y -> v.z) // Evaluate a function and directly assign output to the z-component
)

When a structure is specified as an input argument to a function, the function call does not copy the
instance, but rather copies a reference to the instance. In this way the invocation code can modify the
instance directly. This choice was made for speed - speed being an essential feature of Sexy.

As input references can modify the structures to which they refer, it was not thought necessary to allow
output types to be of structure type (derivatives). This may change in the future, but in the current
implementation, derivatives may not be used as output types.


Related

Wiki: Content