KRL supports integer and real values. A negative number is created by prepending the minus sign (-) to a number.
Strings
String are created by enclosing characters in double quote characters.
Arrays
Arrays are created by enclosing comma-delimited expressions in square brackets like so:
["a","b","c"]
Arrays can be referenced in the usual manner:
a =[1,4,3,6,5];
b = a[1]
This would bind the value 4 to the variable b. Note that array references only work for arrays of one-dimension, so c[1][2] is not allowed (presuming c is an array of arrays).
Hashes
Hashes are creating by enclosing comma-delimted name-value pairs in curly braces like so:
{"foo":"bar","fizz":3,"flop":[1,2,3]}
Extended Quoting
Some KRL statements and expressions make use of extended quotes which begin with << and end the >> For example:
pre {
somevar =<<<p>This is<em>some</em> HTML.<br/><a href="http://www.google.com">Search Google</a></p>>>;}
Extended quotes allow multiple line passages that contain the quote symbol to be entered as variables. Values inside the extended quotes are treated as strings.
Inside the string, variables can be referenced using the #{} syntax for simple templating. These variables are interpreted in the browser, not on the server.
Regular Expressions
Regular expressions are delimited by the slash character ("/") and most closely follow the conventions for Perl regular expressions. The following modifiers may appear after the trailing slash:
i - make the regular expression case insensitive
g - apply the regular expression globally
For example:
p.replace(/foo/,"bar")
would replace the first instance of "foo" in p with "bar".
p.replace(/foo/g,"bar")
would replace all instances of "foo" in p with "bar".
Literals
The following literals can be used within KRL.
Booleans
The boolean values are
trueandfalseNumbers
KRL supports integer and real values. A negative number is created by prepending the minus sign (
-) to a number.Strings
String are created by enclosing characters in double quote characters.
Arrays
Arrays are created by enclosing comma-delimited expressions in square brackets like so:
Arrays can be referenced in the usual manner:
This would bind the value 4 to the variable
b. Note that array references only work for arrays of one-dimension, soc[1][2]is not allowed (presumingcis an array of arrays).Hashes
Hashes are creating by enclosing comma-delimted name-value pairs in curly braces like so:
Extended Quoting
Some KRL statements and expressions make use of extended quotes which begin with
<<and end the>>For example:Extended quotes allow multiple line passages that contain the quote symbol to be entered as variables. Values inside the extended quotes are treated as strings.
Inside the string, variables can be referenced using the #{} syntax for simple templating. These variables are interpreted in the browser, not on the server.
Regular Expressions
Regular expressions are delimited by the slash character ("/") and most closely follow the conventions for Perl regular expressions. The following modifiers may appear after the trailing slash:
For example:
would replace the first instance of "foo" in p with "bar".
would replace all instances of "foo" in p with "bar".