Expressions
Lavender programs are composed of a sequence of expressions. Expressions may span multiple lines if they are enclosed in parentheses, otherwise the expression ends at the next newline character. Examples of expressions include the following.
3 + 5
"Hello world"
def(x) => x + 1
math:sin(2 * math:pi)
Comments
Comments begin with a single quote character and continue until the end of the line. There are no multiline comments.
Literals
Lavender contains three types of literal values: numbers, strings, and vects. Numbers are double precision floating point values, strings are ASCII character sequences, and vects are sequences of values delimited with curly braces ({ }). Strings are always delimited by double quote marks. Strings may contain escape sequences beginning with the backslash character.
| Escape Sequence | Meaning |
|---|---|
\n |
Newline |
\t |
Tab |
\" |
Double quote |
\' |
Single quote |
\\ |
Backslash |
Names
Names may refer to functions or function parameters. Within a function body, function parameter names shadow other names. Names may be either alphanumeric or symbolic. Alphanumeric names begin with a letter or underscore followed by zero or more letters, underscores, or numbers. Symbolic names are made up of the following symbols: ? ~ * / % + - < > = ! & ^ | :. Additionally, names may not be any of the three keywords def, let, or =>. Parameter and namespace names may only be alphanumeric.
| Legal Names | Illegal Names |
|---|---|
hello_world |
_: |
Lavender |
3scary5me |
_impl |
def |
:: |
bar_= |
Qualified Names
Qualified names may be used to refer to functions in another namespace, or to functions that are shadowed by local parameter declarations. Qualified names are given using the following syntax. <namespace> : <name> Qualified names may help to disambiguate functions with the same name in different namespaces.
Name Resolution
When an unqualified name is found, the interpreter attempts to resolve it using the following rules. If the name is the same as a parameter name in the same function, then the name refers to the parameter. Parameters in enclosing functions are next, then functions in the enclosing namespace. Finally, functions in the global and builtin namespaces are checked.
Function Calls
Every expression in Lavender that is not a literal value or function definition is a function call. For example, sin(pi) and 3 * 2 are both function calls with the \math:sin and \global:*\ functions, respectively. Function calls are made up of the function name and an argument list. The function name is placed before the argument list in the case of a prefix function, and inside the argument list in the case of an infix function. Multiple arguments are separated by commas and enclosed in parentheses. Examples below.
> abs(2) ' Calling \math:abs with argument 2.0 2.0 > abs 2 ' Parens are optional with a single argument 2.0 > max(1, 3) 3.0 > max 1, 3 ' Parens are required with multiple arguments Invalid stack > -3 ' Actually calls \global:- -3.0 > -(3) ' Equiv with parens -3.0