Tymless Tutorial: Data



   
  < structures

Aliases

 
locations >
 

Drawing

Control

Data

Reference

 

An alias is a data-type which refers to another variable for its data. To create an alias, use the alias function &, which requires a variable as an argument:

a.x = 2
b = &a.x  // b is an alias of a.x
c = b     // c is also an alias of a.x

To retrieve the value of the aliased variable use the system property .&, e.g.

a.x = 2
b = &a     // b is an alias of a
c = &a.x   // c is an alias of a.x
a.x = 3
d = c.&    // d has the value 3
a.x = 4    // d still has the value 3
d = b.&.x  // d has the value 4

One use of aliases is to pass parameters to a function by reference. All parameters are passed by value, but the value passed can be an alias, e.g.

a=1
b=2
@swap (&a &b)
@swap:
temp = #_1.&
#_1.& = #_2.&
#_2.& = temp

There are some restrictions on using aliases, to prevent private variable aliases 'disappearing' when a child-turtle finishes.

  •  A public variable cannot alias a private variable
  •  A system variable cannot be aliased.


   
  < structures
 
locations >