Skip to content
Turtle Kitty edited this page Jan 28, 2016 · 5 revisions

reader literals

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 -> number

Single 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 comment

The (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))

Clone this wiki locally