MAL文档

语法

  • 空白符 所有的空白符会被忽略
  • , 逗号也会被忽略
  • ; 以分号起始的内容直到行尾都被视为注释
  • 符号
    • 符号中不允许含有空白符及[]{}()'",;`诸特殊字符
    • 符号亦不得以~@^诸特殊字符开头
    • :开头的符号称为关键字,可以用作字典的键
    • 按照惯例,!结尾的符号表示副作用,?结尾的符号表示谓词
    • 符号中可以使用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)
    
    定义ab,求值并返回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中,定义a1b1a2b2,… 且后方绑定可以引用前方绑定。
    最终求值并返回body.
  • do 顺序执行
    (do a1 a2 ... an)
    
    顺序执行a1 a2 ...,最终求值并返回an.
  • if 条件分支
    (if cond true_clause)
    (if cond true_clause false_clause)
    
    如果condnilfalse以外的其他值,求值并返回true_clause,否则求值并返回false_clause(如果存在)或nil.
  • fn* 匿名函数 / 闭包
    (fn* params body)
    (fn* (p1 p2 & rest) body
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值