123 ; the integer one hundred twenty-three
3/7 ; the ratio three-sevenths
1.0 ; the floating-point number one in default precision
1.0e0 ; another way to write the same floating-point number
1.0d0 ; the floating-point number one in “double” precision
1.0e-4 ; the floating-point equivalent to one-ten-thousandth
+42 ; the integer forty-two
-42 ; the integer negative forty-two
-1/4 ; the ratio negative one-quarter
-2/8 ; another way to write negative one-quarter
246/2 ; another way to write the integer one hundred twenty-three
“foo” ; the string containing the characters f, o, and o.
“fo\o” ; the same string
“fo\\o” ; the string containing the characters f, o, \, and o.
“fo\”o” ; the string containing the characters f, o, “, and o.
双引号”需要转义 \”
斜杠本身\需要转义\\
不能在lisp names出现的字符:( ) ” ‘ ` , : ; \ |
连字符 – 在Lisp中被允许使用
全局变量以 * 开始 如 *db*
常变量以 + 开始和结束
Lisp语言标准允许的变量字符包括 a-z * + – / 1 2 < = > &
x ; the symbol X
() ; the empty list
(1 2 3) ; a list of three numbers
(“foo” “bar”) ; a list of two strings
(x y z) ; a list of three symbols
(x 1 “foo”) ; a list of a symbol, a number, and a string
(+ (* 2 3) 4) ; a list of a symbol, a list, and a number.
(defun hello-world ()
(format t “hello, world”))
空表是合法的 比如 ()
内置常量 PI T NIL T– true NIL–false
:.NAME 5 定义固定常量 NAME 值为 5 在之后的表达式使用NAME,值为5,且修改无效
:.NAME 5 :.NAME 6 (* NAME 3) output 15
1、Function calls
(function-name argument*) 每个argument都必须是一个合法的Lisp变量 各个argument依次被evaluate
(+ 1 2) (* (+ 1 2) (- 3 4))
特殊操作符(so-called special operators),在argument被evaluate之前进行控制:IF
(if test-form then-form [else-form]) 三个参数,第三个可选,首先执行第二个参数,如果T则执行第二个参数
QUOTE
(quote (+ 1 2)) 直接返回后面的参数 等价于 ‘(+ 1 2)
2、Macros
The evaluation of a macro form proceeds in two phases: First,
the elements of the macro form are passed, unevaluated, to the macro function. Second, the
form returned by the macro function—called its expansion—is evaluated according to the
normal evaluation rules.
T t ‘t
NIL () ‘() NIL ‘NIL
= 数字是否相等
eq eql “use EQ when possible” “always use EQL” 都仅仅对数字和字符串有效
equal equalp equal 区别大小写 equalp不区别大小写
注释
四个分号在文件头注释
;;;;math package
三个分号在段落前注释
;;;
两个分号注释
;;
一个分号在行末注释
;
;;;; Four semicolons are used for a file header comment.
;;; A comment with three semicolons will usually be a paragraph
;;; comment that applies to a large section of code that follows,
(defun foo (x)
(dotimes (i x)
;; Two semicolons indicate this comment applies to the code
;; that follows. Note that this comment is indented the same
;; as the code that follows.
(some-function-call)
(another i) ; this comment applies to this line only
(and-another) ; and this is for this line
(baz)))