Syntax
Expressions, literals, quoting, and comments.
Expressions
Sigil code consists of expressions. Every expression evaluates to a value.
42 ; number literal
"hello" ; string literal
(+ 1 2) ; procedure call
(if (> x 0) "pos" "neg") ; conditionalProcedure calls use prefix notation: (operator operand ...).
Literals
Numbers
42 ; integer
-17 ; negative integer
3.14159 ; floating point
1.5e10 ; scientific notation
#xff ; hexadecimal (255)
#b1010 ; binary (10)
#o755 ; octal (493)Integers are 62-bit signed on 64-bit platforms. Floating point uses IEEE 754 double precision.
Strings
Strings are enclosed in double quotes. They store UTF-8 text internally.
"hello, world"
"line one\nline two" ; newline escape
"tab\there" ; tab escape
"quote: \"hi\"" ; escaped quote
"unicode: \u03BB" ; lambda characterEscape sequences:
\nnewline,\ttab,\rcarriage return\\backslash,\"double quote\xNNhex byte,\uNNNNunicode code point
Characters
Characters represent single Unicode code points.
#\a ; lowercase a
#\Z ; uppercase Z
#\space ; space character
#\newline ; newline
#\tab ; tab
#\x03BB ; lambda by hex codeBooleans
#t ; true
#f ; falseOnly #f is false in conditionals; everything else (including 0, "", '()) is true.
Symbols
Symbols are interned identifiers. They're often used as keys or enum values.
'hello ; quoted symbol
'with-hyphen ; hyphens are valid
'+ ; operators are symbols tooLists
Lists are built from pairs (cons cells). The empty list is '(). Lists are the primary sequence type in Sigil.
'(1 2 3) ; list of numbers
'(a b c) ; list of symbols
'(1 "two" three) ; mixed types
(list 1 2 3) ; same as '(1 2 3)
(cons 1 '(2 3)) ; => (1 2 3)Pairs
A pair holds two values: car (first) and cdr (rest).
(cons 'a 'b) ; => (a . b) - dotted pair
(car '(a . b)) ; => a
(cdr '(a . b)) ; => bVectors
Vectors are fixed-size mutable arrays with O(1) random access.
#(1 2 3) ; vector literal
(vector 1 2 3) ; same as #(1 2 3)
(vector-ref #(a b c) 1) ; => bArrays
Sigil arrays use #[...] syntax and provide O(1) indexed access with persistent (immutable) semantics.
#[1 2 3] ; array literal
(array 1 2 3) ; same as #[1 2 3]
(array-ref #[a b c] 0) ; => aDicts
Dicts are hash maps with keyword keys.
#{ name: "Alice" age: 30 } ; dict literal
(dict name: "Alice" age: 30) ; same thing
(dict-ref d name:) ; => "Alice"
(dict-set d city: "Boston") ; returns new dictQuoting
Quote (') prevents evaluation:
'hello ; symbol hello, not variable lookup
'(1 2 3) ; list, not procedure callQuasiquote ( `) allows selective evaluation within a quoted template:
`(1 2 ,(+ 1 2)) ; => (1 2 3)
`(a ,@'(b c) d) ; => (a b c d) - splicingComments
; line comment - everything to end of line
#; (this entire expression is commented out)
#|
Block comment.
Can span multiple lines.
|#Use ;; for section headers and internal notes, ;;; for docstrings on exported definitions.