Assignment by Value
We use the “=” sign to imply the assignment by value. It makes a new copy of the object in memory and assigns it to the new variable.
Syntax
For variables:
<variable>=<object>
or
<variable>[index]=<object>
For constant variables:
const <variable>=<object>
Examples
$ y=6 4 7
[6,4,7]
$ x=y;
$ x;
[6,4,7]
$ y[1]=0;
[6,0,7]
$ x;
[6,4,7]
// modifying y does does not affect x
$ const a=10;
Release an object: <variable>=NULL or use the undef command. Sometimes, to reduce the footprint of an application, we would like to release some variables from the system memory.
$ x=6 4 7;
$ x;
[6,4,7]
$ x=NULL;
$ x;
NULL
$ x=6 4 7;
$ undef(`x, VAR);
$ x;
Syntax Error: [line #1] Cannot recognize the token x
DolphinDB also supports the following assignment operators: +=, -=, *=, /= and =.
$ x=0;
$ x+=5;
$ x;
5
// equivalent to x=x+5
$ x=5;
$ x-=2;
$ x;
3
// equivalent to x = x - 2
$ x=5
$ x*=5;
$ x;
25
// equivalent to x = x * 5
$ x=5;
$ x/=2;
$ x;
2
// equivalent to x = x / 5.
$ x=5;
$ x\=2;
$ x;
2.5
$ x=1 2 3 4 5;
$ x[1 3]+=10;
$ x;
[1,12,3,14,5]