References - Manhunter07/MFL GitHub Wiki

References are pointer values that address either a variable, function or type. Their value can be a reference to either a declared variable, a declared function, a declared type or an anonymous function.

Unassignd references are represented by the special value of Nil. Such cannot be de-referenced: de-referencing an unassigned reference causes an exception.

Creating a reference

Syntactically, references are created in three different ways:

  • References to declared (named) addressable objects (like variables) are created using the @ symbol in front of the identifier:
    @MyVar
    @System.TypeOf
    @RoundRange
    
    This procedure is called addresing and is the most common way of creating a reference.
  • References to anonymous functions are created using the func-ret statement:
    func A, B ret A + B
    func |S|: string(256) ret -S
    func X, N: Number = 1 ret X ^ N
    
  • References to anonymous types are created using the @ symbol in front of a type constructor:
    @string
    @enum(Null, True)
    @record(X, Y, Z)
    

In addition to that, there exist a few special functions that return references, like ConstructorOf that returns a reference to the constructor of a given type, passed by reference.

Operators

See also: Operators#References

Unary

Operator Operation
? Signus

The signus of a reference is 0 for unassigned references (Nil) or 1 otherwise.

Binary

Operator Operation
? Comparison
?= Equality

Comparison

First operand Second operand Result
Nil Nil 0
Nil Not Nil -1
Not Nil Nil 1
Not Nil Not Nil 0

The comparison (?) of two references returns the comparison result of their signuses. This is 0 for two identical operands, -1 if only the first operand is unassigned (Nil) or 1 if only the second operand is unassigned (Nil).

Type check

Like any other data type, references support the type compatibility check operator (?:). It returns True on supported reference types, but also any other type that supports the respected value(s).

See also

⚠️ **GitHub.com Fallback** ⚠️