Touch Develop retirement postponed until June 22, 2019. Sign-in and access to cloud assets to be removed on May 23, 2018.Learn More..


A value of Ref type represents a reference (pointer) to a storage location, e.g., a field of an object or a global variable.
Once you have a regular value of type Ref you can use the properties listed at the end of this article to read or write it. For example:
p : Ref of Number)
var x := p → ◈get
p → ◈set(x * 2)
end function
You can notice that all the properties start with the diamond symbol. This is because they are a bit special. Normally a value of type String would have properties available like →contains, →to upper case etc. However, if the value happens to be a a reference to a field or a global variable, it additionally gets all the methods of the Ref type. The diamond symbol is used to avoid a mix-up.
The →◈get and →◈set properties are not very useful in this context but can still be used. For example the following two lines do the same thing (k is a global Number variable):
 k :=  k + 1
 k → ◈set( k → ◈get + 1)
Other properties may be more useful, for example the following line does a similar thing to the previous two, but with better handling of conflicts when the data is stored in the cloud:
 k → ◈add(1)
The most typical use of the diamond properties is →◈ref, which is needed when you want to create a Ref from a storage location:
 double( k → ◈ref)

Ref of ...

Refs can be created for any type. Ref of Number gets additional property →◈add and Ref of String gets additional property →◈test and set (set to the specified value if empty now).

Ref as a regular value

Above we are using k as both a Number and a Ref of Number. It is called an implicit conversion and works for global variables and record field references.
There is no implicit conversion when we have a regular value of type Ref of ... as in the double example above. It would be an error to write p * 2 there, we always use p→◈get * 2 in such case.