AtlatestRepositorysigil-web-styles
sigil-web-styles / tree / build / dev / lib / _pkg / sigil-stdlib / languagesyntax.md
2
# Syntax4
> Expressions, literals, quoting, and comments.6
## Expressions8
Sigil code consists of expressions. Every expression evaluates to a value.10
```scheme11
42 ; number literal12
"hello" ; string literal13
(+ 1 2) ; procedure call14
(if (> x 0) "pos" "neg") ; conditional15
```17
Procedure calls use prefix notation: `(operator operand ...)`.19
## Literals21
### Numbers23
```scheme24
42 ; integer25
-17 ; negative integer26
3.14159 ; floating point27
1.5e10 ; scientific notation28
#xff ; hexadecimal (255)29
#b1010 ; binary (10)30
#o755 ; octal (493)31
```33
Integers are 62-bit signed on 64-bit platforms. Floating point uses IEEE 754 double precision.35
### Strings37
Strings are enclosed in double quotes. They store UTF-8 text internally.39
```scheme40
"hello, world"41
"line one\nline two" ; newline escape42
"tab\there" ; tab escape43
"quote: \"hi\"" ; escaped quote44
"unicode: \u03BB" ; lambda character45
```47
Escape sequences:48
- `\n` newline, `\t` tab, `\r` carriage return49
- `\\` backslash, `\"` double quote50
- `\xNN` hex byte, `\uNNNN` unicode code point52
### Characters54
Characters represent single Unicode code points.56
```scheme57
#\a ; lowercase a58
#\Z ; uppercase Z59
#\space ; space character60
#\newline ; newline61
#\tab ; tab62
#\x03BB ; lambda by hex code63
```65
### Booleans67
```scheme68
#t ; true69
#f ; false70
```72
Only `#f` is false in conditionals; everything else (including `0`, `""`, `'()`) is true.74
### Symbols76
Symbols are interned identifiers. They're often used as keys or enum values.78
```scheme79
'hello ; quoted symbol80
'with-hyphen ; hyphens are valid81
'+ ; operators are symbols too82
```84
### Lists86
Lists are built from pairs (cons cells). The empty list is `'()`. Lists are the primary sequence type in Sigil.88
```scheme89
'(1 2 3) ; list of numbers90
'(a b c) ; list of symbols91
'(1 "two" three) ; mixed types92
(list 1 2 3) ; same as '(1 2 3)93
(cons 1 '(2 3)) ; => (1 2 3)94
```96
### Pairs98
A pair holds two values: car (first) and cdr (rest).100
```scheme101
(cons 'a 'b) ; => (a . b) - dotted pair102
(car '(a . b)) ; => a103
(cdr '(a . b)) ; => b104
```106
### Vectors108
Vectors are fixed-size mutable arrays with O(1) random access.110
```scheme111
#(1 2 3) ; vector literal112
(vector 1 2 3) ; same as #(1 2 3)113
(vector-ref #(a b c) 1) ; => b114
```116
### Arrays118
Sigil arrays use `#[...]` syntax and provide O(1) indexed access with persistent (immutable) semantics.120
```scheme121
#[1 2 3] ; array literal122
(array 1 2 3) ; same as #[1 2 3]123
(array-ref #[a b c] 0) ; => a124
```126
### Dicts128
Dicts are hash maps with keyword keys.130
```scheme131
#{ name: "Alice" age: 30 } ; dict literal132
(dict name: "Alice" age: 30) ; same thing133
(dict-ref d name:) ; => "Alice"134
(dict-set d city: "Boston") ; returns new dict135
```137
## Quoting139
Quote (`'`) prevents evaluation:141
```scheme142
'hello ; symbol hello, not variable lookup143
'(1 2 3) ; list, not procedure call144
```146
Quasiquote (`` ` ``) allows selective evaluation within a quoted template:148
```scheme149
`(1 2 ,(+ 1 2)) ; => (1 2 3)150
`(a ,@'(b c) d) ; => (a b c d) - splicing151
```153
## Comments155
```scheme156
; line comment - everything to end of line158
#; (this entire expression is commented out)160
#|161
Block comment.162
Can span multiple lines.163
|#164
```166
Use `;;` for section headers and internal notes, `;;;` for docstrings on exported definitions.