Home Online Manual
Top
Back: countedref
Forward: reference expressions
FastBack: pyobject
FastForward: Functions and system variables
Up: countedref
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.28.1 reference declarations

Syntax:
reference name = identifier ;

Purpose:
defines a reference object.

Default:
None

Example:
 
system("reference"); system("shared");
  reference empty;
  empty;
==> <unassigned reference or shared memory>

  string str = "Hello World!";
  reference ref = str;
  ref;
==> Hello World!
==> 
  ref = 17;    // cannot change type of 'i'
==>    ? `string`(str) = `int` is not supported
==>    ? expected `string` = `string`
==>    ? error occurred in or before ./examples/reference_declarations.sing l\
   ine 8: `  ref = 17;    // cannot change type of 'i'`
  list ll= list(4, 5, 6);
  reference lref = ll[2];
  lref;
==> 5
==> 
  lref = str;  // change list element
  ll;
==> [1]:
==>    4
==> [2]:
==>    Hello World!
==> [3]:
==>    6