-
Notifications
You must be signed in to change notification settings - Fork 4
reader
The Sexy reader recognizes several data structures.
It reads null, true, false, and numbers as themselves.
null -> null
true -> true
false -> false
2 -> int
6.28 -> number
1/2 -> numberSingle characters preceded by a dollar sign are read as runes.
\f -> rune
Quoted strings of characters are read as texts.
"Shallow Then Halo"There are also the (text: ...) and (template: ...) forms for generating texts.
(text: ((\w+)\s*:\s*((\w+)&(\d+))))
-> "((\\w+)\\s*:\\s*((\\w+)&(\\d+)))"
(let (x 2 y 3)
(template: x: {{ x }} y: {{ y }} (z: {{ (+ x y) }})))
-> "x: 2 y: 3 (z: 5)"List literals are interpreted as code unless quoted, except for the empty list (), which is self-evaluating.
(foo bar baz) ; apply function foo to arguments bar and baz
(quote (foo bar baz)) -> (foo bar baz)The single-quote (') is shorthand for (quote ...).
'foo -> (quote foo)
'(x y z) -> (quote (x y z))The percent sign (%) is shorthand for (qq ...).
Within a qq, dollar-sign ($) and at-sign (@) are shorthand for (unq ...) and (unqs ...).
For old Lisp hackers, ` and , also work. ,@ is just @, however.
(def x 1)
(def y (list 2 3))
%(foo x y $x $y @y)
-> (qq (foo x y (unq x) (unq y) (unqs y)))
-> (foo x y 1 (2 3) 2 3)Semicolons comment out the rest of a line.
(+ 1 2) ; this is a commentThe (rem: ...) form comments out multple lines.
(rem:
This module is a hack, and a really bad idea, but I'm short on time.
(this list is never evaluated.))
(pair: ...), (vector: ...), and (record: ...) read in literal structures.
(pair: x y) -> (pair 'x 'y)
(record: x 1 y 2 z (+ x y)) -> (record 'x 1 'y 2 z '(+ x y))
(vector: x y z (1 2 3)) -> (vector 'x 'y 'z (list 1 2 3))