开发者生态
morning
超多语言 Lisp:Common Lisp、Racket、Clojure、Emacs Lisp
2026-05-18
1 阅读
veqq
Hyperpolyglot Lisp:Common Lisp、Racket、Clojure、Emacs Lisp c 并排参考表语法和执行 |变量和表达式 |算术与逻辑|字符串|正则表达式 |日期和时间 |列表 |固定长度数组 |字典 |用户定义类型 |功能|执行控制|例外 |溪流 | emacs 缓冲区 |文件 |目录 |流程与环境|库和命名空间|对象| lisp 宏 |反思| java interop common lispracket clojure emacs lisp 使用的版本 SBCL 1.2 Racket 6.1 Clojure 1.6 Emacs 24.5 显示版本 $ sbcl -- 版本 $racket -- 启动时 repl 显示的版本 $ emacs -- 版本语法和执行 common lispracket clojure emacs lisp 编译器 $ raco make module .rkt M-x 字节编译文件独立可执行文件(sb-ext:save-lisp-and-die "executable " :executable t :toplevel ' function ) $ mzc —exe 可执行文件解释器 $ sbcl -- script foo.lisp $racket -r foo.racket 指定 clojure jar 的完整路径: java -cp clojure.jar clojure.main foo.clj shebang #!/usr/bin/env sbcl -- script #!/usr/bin/envracket -- 脚本指定 clojure jar 的完整路径: #!/usr/bin/env java -jar clojure.jar #!/usr/bin/env emacs -- 脚本 repl $ sbcl $racket $ java -jar /PATH/TO/clojure.jar M-x ielm 命令行程序 $racket -e '(+ 1 1)' 单词分隔符 空白 空白 空白和逗号 空白 行尾评论 (+ 1 1) ;添加 (+ 1 1) ;添加 (+ 1 1) ;添加 (+ 1 1) ;添加多行注释 (+ 1 #| 添加 |# 1) (+ 1 #| 添加 |# 1) 变量和表达式 common lispracket clojure emacs lisp 标识符 不区分大小写,不能以排除数字的字符开头: SP ( ) " , ' ` : ; # | \ 保留用于用户宏: ? ! [ ] { } 区分大小写,不能以排除数字的字符开头: SP ( ) [ ] { } " , ' `; #| \ 区分大小写,不能以数字开头允许的字符:A-Z a-z 0-9 * + ! -_?这些具有特殊含义或被保留: / 。 : 区分大小写,不能以数字排除字符开头: SP ( ) " , ' ` ; # | \ _ [ ] 带引号的标识符和转义标识符 (setq |空白符号| 3) (setq white\ space\ 符号 3) (define |空白符号| 3) (define White\ space\ 符号 3) none none none (setq white\ space\ 符号 3) 局部变量 ; 并行赋值: (let ((x 3) (y 4)) (+ x y)) ; 顺序赋值: (let* ((x 3) (y (* x x))) (+ x y)) ; 并行赋值: (let ((x 3) (y 4)) (+ x y)) ; 顺序赋值: (let* ((x 3) (y (* x x))) (+ x y)) (let [x 3 y 4] (+ x y)) (let [[x y] [3 4]] (+ x y)) (let [x 3 y (* x x)] (+ x y)) ; 并行赋值: (lexical-let ((x 3) (y 4)) (+ x y)) (lexical-let* ((x 3) (y (* x x))) (+ x y)) 全局变量 (defparameter *x* 3) ; 如果已设置,则不会更改 x: (defvar *x* 3) (define x 3) ; y 不是全局的: (define (double z) (define y 2) (* y z)) (def x 3) (set 'x 3) (setq x 3) 删除变量 (makunbound 'x) (namespace-undefine-variable! 'x) (ns-unmap *ns* 'x) (makunbound 'x) null nil '() null '() ; 与 Java 中的 null 相同: nil nil '() null test (null x) (null? x) (nil? x) (null x) 标识符作为值 'x (quote x) 'x (quote x) 'x (quote x) 'x (quote x) 标识符测试 (symbolp 'x) (symbol? 'x) (symbol? 'x) (symbolp 'x) 标识符相等test (eq 'x 'x) (eq? 'x 'x) (= 'x 'x) (eq 'x 'x) 非引用标识符 :foo #:foo :foo :foo 标识符属性 set、get、remove (set 'x 13) (setf (get 'x :desc) "unlucky") (get 'x :desc) (remprop 'x :desc) none ; clojure.lang.IObj 的实例: (def x (with-meta [13] {:desc "unlucky"})) (get (meta x) :desc) ; none (set 'x 13) (setf (get 'x :desc) "unlucky") (get 'x :desc) (remprop 'x :desc) 算术和逻辑 Common lispracket clojure emacs lisp true and false t nil #t #f true false true false t nil falsehoods nil () #f false false nil nil () 逻辑运算符 (or (not t) (and t nil)) (or (not #t) (and #t #f)) (or (not true) (and true false)) (or (not t) (and t nil)) 关系运算符 = /= < > <= >= none < > <= >= = not= < > <= >= = /= < > <= >= min 和 max (min 1 2 3) (max 1 2 3) (min 1 2 3) (max 1 2 3) (min 1 2 3) (max 1 2 3) (min 1 2 3) (max 1 2 3) 数值