Skip to content

Reference

Edward Palmer edited this page Jan 5, 2025 · 5 revisions

References in Eucleia can be used to avoid deep-copying an object. Unlike Python, objects are implicitly copied unless a reference is explicitly used. References will be created in the same scope or a child-scope or any object they are linked to so there will be no issue with lifetimes. Additionally, references once bound to an object cannot be unbound or pointed to another.

Examples

Int reference:

int a = 3;
int &aRef = a;

aRef = 4; # now, a == 4

Array reference:

array someArray = [1, 2, 3];
array &arrayRef = someArray;

Caveats

  • Currently, we cannot have references to a struct/class member variable or an array member. This will be addressed in a later version.
  • No function argument references (so always pass by value which is not-ideal!). This will be addressed later.
  • No type checking for struct/class types.

Clone this wiki locally