Local variables can be assigned values using the @asn and $asn functions, the ASNand ASNS commands, or directly using the "short form of assignment", like @x=2 or $x="some string".
Global variables can be assigned values using the @gasn and $gasn functions, the GLOBALand GLOBALSTR commands, or using the short form of global assignment, like @@x=2 or $$x="test string". Globals can also be assigned using the various List-related commands like ENLIST, ENLIST_, SETITEM, SETITEM_, etc., because all List variables are global in scope. NOTE that the double @@ or $$ is only used for assignment, not for reference. In other words, @x or $x could refer to either a local and global variable, depending on Scope.
Variable names can be unquoted if they contain only letters, numbers or the underscore, and begin with a letter. Examples:
(Equivalent; assigns 42 to local variable @x.)Variable names can be "nonstandard" and contain other characters if they are quoted, for example:
@asn[x,42];
ASN x=42;
@x=42;(Equivalent; assigns 12 to local variable @myvariablename.)
@asn[myvariablename,12];
ASN myvariablename=12;
@myvariablename=12;(Equivalent; assigns 22 to local variable @x_16.)
@asn[x_16,22];
ASN x_16=22;
@x_16=22;(Equivalent; assigns "here's a string" to local variable $x.)
$asn[x,"here's a string"];
ASNS x="here's a string";
$x="here's a string";(Equivalent; assigns 272.3 to global variable @n.)
@gasn[n,272.3];
GLOBAL n=272.3;
@@n=272.3;(Equivalent; assigns "look, another string!" to global variable $n.)
$gasn[n,"look, another string!"];
GLOBALSTR n="look, another string!";
$$n="look, another string!";
@asn["This is some strange variable name!",18];Variable names can also be specified using a string variable, like this:
or
ASN "This is some strange variable name!"=18;(The short form of assignment could not be used in this case.)
$z="this will be the variable name"; (Assigns "this will be the variable name" to local variable $z.)…which would assign the value 14 to a variable named this will be the variable name! In this case you would only be able to refer to the variable using the @var function, not directly. In other words, you could NOT refer to the variable in the above example as @"this will be the variable name".
ASN $z=14; (Assigns 14 to local numeric variable named "this will be the variable name".)
Variables with standard names (no spaces, etc.) can be referred to
directly
(for example @x or $s). Any variable of the appropriate type can be
referred
to using the @var and $var
functions. Be careful when using @var and $var that you give the
variable
name itself as the argument, and not a reference to the
variable.
In other words, to get the value of $x, you would use $var[x], and NOT
$var[$x]!
You can also use the @v_ and $v_ functions in place of @var and
$var, the difference being that @v_ and $v_ will not cause an error if
the variable doesn't exist, the way that @var and $var will.
Instead, @v_ and $v_ will return 0 or "" (empty string), respectively,
if the variable doesn't exist. Also, @g_ and $g_ can be used like
@v_ and $v_ to access global variables, specifically.
See ASN , GLOBAL, ASNS and GLOBALSTR in the Actions section.