安装环境
$ brew install sbcl
安装完毕后使用 sbcl 启动交互环境。 sbcl 这是一个REPL(read–eval–print loop )。
开始Common Lisp编程:
$ sbcl
This is SBCL 1.5.6, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* 1
1
* 1+2
debugger invoked on a UNBOUND-VARIABLE in thread
#<THREAD "main thread" RUNNING {10004F04C3}>:
The variable |1+2| is unbound.
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE ] Retry using |1+2|.
1: [USE-VALUE ] Use specified value.
2: [STORE-VALUE] Set specified value and use it.
3: [ABORT ] Exit debugger, returning to top level.
简单数字计算
0] (+ 1 2)
3
0] (* 99 99)
9801
定义函数
(defun avg (x1 x2 x3)
(/ (+ x1 x2 x3) 3))
(avg 100 80 70)
250/3
在 Lisp 的另外一个方言 Clojure 上:
user=> (defn avg [x1 x2 x3]
(/ (+ x1 x2 x3) 3))
user=> (avg 12 13 14)
13
Kotlin 开发者社区
国内第一Kotlin 开发者社区公众号,主要分享交流:编程语言、Spring Boot、Android、React.js/Node.js、函数式编程、编程思想、系统架构设计、领域建模等相关主题。