语法
- 空白符 所有的空白符会被忽略
,
逗号也会被忽略;
以分号起始的内容直到行尾都被视为注释- 符号
- 符号中不允许含有空白符及
[]{}()'",;`
诸特殊字符 - 符号亦不得以
~@^
诸特殊字符开头 - 以
:
开头的符号称为关键字,可以用作字典的键 - 按照惯例,
!
结尾的符号表示副作用,?
结尾的符号表示谓词 - 符号中可以使用unicode字符(包括emoji)
- 符号中不允许含有空白符及
- 数字
- 目前仅支持整数,尚不支持浮点数
- 字符串
- 有限的unicode支持
读取器宏
()
/[]
/{}
/""
列表/向量/字典/字符串'
/~
/~@
/`
引号/解引号/解引号并展平/反引号@
解原子引用^
元数据
特殊形式
Lisp “specials” (or “special atoms”) which means that they are language level features and more specifically that the rest of the list elements (arguments) may be evaluated differently (or not at all) unlike the default apply case where all elements of the list are evaluated before the first element is invoked. Lists which contain a “special” as the first element are known as “special forms”. They are special because they follow special evaluation rules.
def!
定义符号
定义(def! a b)
a
为b
,求值并返回b
The!
suffix on symbols is used to indicate that this symbol refers to a function that mutates something else.let*
定义块
在(let* (a1 b1 a2 b2 ...) body)
body
中,定义a1
为b1
,a2
为b2
,… 且后方绑定可以引用前方绑定。
最终求值并返回body
.do
顺序执行
顺序执行(do a1 a2 ... an)
a1 a2 ...
,最终求值并返回an
.if
条件分支
如果(if cond true_clause) (if cond true_clause false_clause)
cond
为nil
或false
以外的其他值,求值并返回true_clause
,否则求值并返回false_clause
(如果存在)或nil
.fn*
匿名函数 / 闭包(fn* params body) (fn* (p1 p2 & rest) body