Lexical Structure
Namespace Resolution
Section titled “Namespace Resolution”lash uses two separate namespaces resolved by syntactic position (Lisp-2 design):
- Command namespace: built-in methods, user-defined functions, and external binaries from
$PATH. - Variable namespace: variables declared with
letormut.
A name in the first-word position of a statement resolves in the command namespace. A name in expression context (assignment RHS, conditions, lambda bodies, chain arguments) resolves in the variable namespace.
Command namespace resolution order:
- Built-in functional method (e.g.,
sort,filter,map) - User-defined function
- External binary from
$PATH
A variable and a command can share the same name without collision:
let grep = "my pattern"grep "foo" file.txt # command namespace: /usr/bin/greplet result = grep # variable namespace: the variableecho "pattern: $grep" # string interpolation: the variableTo use a command in expression context, wrap it in backticks (see Functional Chains).
Quoting and Escaping
Section titled “Quoting and Escaping”lash supports three quoting styles:
Double Quotes
Section titled “Double Quotes”String with interpolation:
echo "hello $name"echo "hello ${name}"echo "result: $((count + 1))"echo "literal \$sign"Single Quotes
Section titled “Single Quotes”Literal string, no processing:
echo 'no $interpolation'echo 'no \escapes'Backticks
Section titled “Backticks”Command execution and functional bridge (not POSIX command substitution):
let files = `ls -la``ls -la`.sort().take(5)Escape Sequences
Section titled “Escape Sequences”Available inside double-quoted strings only:
| Sequence | Meaning |
|---|---|
\n | Newline |
\t | Tab |
\\ | Literal backslash |
\$ | Literal dollar sign |
\" | Literal double quote |
Bare Words
Section titled “Bare Words”In command position, unquoted words are literal arguments. In expression context, unquoted words resolve as variable names.
Command Substitution
Section titled “Command Substitution”Backticks are reserved for the functional bridge. Command substitution uses $():
echo "today is $(date)"let branch = $(git branch --show-current)Environment Variable Prefixes
Section titled “Environment Variable Prefixes”Uppercase names before a command set environment variables for that command only:
DFLAGS="-O2" dub build --compiler=ldc2CC=gcc CFLAGS="-Wall" makeOnly names matching [A-Z][A-Z0-9_]* are recognized as env var prefixes. Lowercase names are treated as commands.