Last Updated: February 25, 2016
·
828
· dionysios

Aliases in Q

In Q, the alias function (::) makes a variable point to another one, so that we can refer to it by a different name.

For example:

a : 3
b :: a
a: 5
b    /b is now equal to 5

But the alias is only one-way, if b is amended, a does not change along with it. Continuing with the previous assignments:

b: 7
a        /a remains equal to 5
a : 11
b        /b remains equal to 7 - not an alias any more

The interpreter does not allow bidirectional alias relationship. It will detect cycles and issue an error:

a: 13
b:: a      /OK
c:: b      /OK
a:: c      / 'loop 

For variables that do not hold one atom, like a list, dictionary or table, one cannot amend individual components:

L: 1 2 3
M :: L
M[1] : 4    /`type