-
Notifications
You must be signed in to change notification settings - Fork 0
Special Variables
In ShinyLisp, most characters can be used in variable names. Any ASCII character that is not considered "special" or "uppercase" to the language can be used in variable names. Unicode support is coming soon. The following are special characters and cannot be used in variable names.
-
0123456789
- The digits are always parsed as numbers and cannot be used anywhere in variable names. This is to allow chains to include numeric literals. -
()[]{}
- Parentheses and other brackets are used for special syntactic list-like constructs. -
:~
- Colon is used to force uppercase status and tilde is used to force the end of a list. -
'"
- Single quotes are used to quote symbols, and double quotes are used to quote strings. -
\t\n\r
- Whitespace characters can never be in variable names, as they are always parsed as whitespace. -
.
- The dot is used for literal cons cell construction and may in the future be used as a decimal point. -
\
- A backslash is used as a negative sign for numeric literals, since the minus sign is used as a word separator in function names.
By default, variables in ShinyLisp are local to the function in which they are defined. The =
operator will assign variables, defining a new variable in the current scope as necessary. Inner functions have access to their outer function's closure, and variable bindings are resolved lexically. The variable %
and any variable beginning with the #
character are declared implicitly global. Unless they are explicitly defined with define
, they will always be declared globally, no matter where they are first assigned.
The variable #,
is used when puts
(or similar) needs to output a list and is treated as the list delimiter. It's default value is
, a single space. Less frequently, one might need to modify #,,
, which is the dot delimiter. It's default value is .
, a dot surrounded by spaces, and is used when a dotted list is encountered in puts
.
In a script file (but not in the REPL), if the script terminates normally, the value of the %
variable is implicitly printed at the end of execution, if a variable with that name exists. This is to make it more convenient to write scripts which do some work and then prints the result, as the final print statement can be omitted in this case.
The variable with the name !!
always refers to the argument list of the immediately enclosing function. For convenience, each argument is also provided separately. The first three arguments are x
, y
, then z
, followed by xx
, yy
, and zz
. If more than six arguments are needed, the variables xxa
, yya
, zza
xxb
, yyb
, zzb
, xxc
, yyc
, zzc
... xxz
, yyz
, zzz
are bound to the next arguments. If, inexplicably, you need more than 84 arguments, the pattern continues with xxaa
, yyaa
, zzaa
, xxab
, yyab
, zzab
, ..., but if you are using a variable called xxadz
as an argument, it might be appropriate to reconsider your approach. Note that at the top level of the program, the argument variables will be bound to the command line arguments.
Similarly, when a regex match or substitution is performed, the variable r!
is bound to the list of subgroup captures, and rx
, ry
, rz
, rxx
, ... are bound to the individual captures. Likewise, rr
is bound to the full match text.