elisp 基础

形式

(谓词 参数 参数 参数 ...)

 

 

基本运算符 加 减 乘 除 模 指数

(+ 34 98 20)

152

 

(- 100 20 30)

50

 

(* 10 20 30)

6000

 

(/ 10 2 5)

1

 

(% 17 10)

7

 

(expt 2 10)

1024

 

判断类型(还有很多种判断谓词)

(integerp 10)

t

(integerp 1.1)

nil

 

(floatp 10)

nil

(floatp 1.1)

t

 

elisp为判断为假的东西 和C等 语言有点不同

nil
()
'()
(list)
都是表示假 除了这些都为真 所以0是真的
比较运算符(该有的都有 不全部列举)
(< 1 2)
t
(= 3 3)
t
(>= 3 1)
t

字符串的比较运算符(就这两个比较符)
(string= "hello lisp" "hello lisp")
t
(string< "hello lisp" "hello elisp")
nil

全局变量与局部变量
;setq 这样设置全局变量 x,y,z 为 1,2,3
(setq x 1 y 2 z 3)
;let 用来设置局部变量
;(let (‹var1› ‹var2› …) ‹body›)
(let (a b)
  (setq a 1)
  (setq b 3)
  (+ a b))
4
;(let ((‹var1› ‹val1›) (‹var2› ‹val2›) …) ‹body›)
;作用同上
(let ((a 1) (b 3))
  (+ a b))
4
;if语句 
;(if ‹test› ‹true body› ‹false body›)
;<false body>可要可不要
(if (> 2 1) (message "yes") (message "no"))
"yes"
;when
;(when ‹test› ‹expr1› ‹expr2› …)
;when和if语句都是判断语句
(when (> 2 1)
  (setq a 10);a是全局变量 只有a在let里面(setq a 10)才是局部变量
  (setq b 30)
  (+ a b))
;while
;(while ‹test› …)
;循环语句
(setq i 99)
99
(while (> i 50)
  (setq i (1- i)))
nil
(= i 50)
t
;函数定义
(defun Function (arg1 arg2 …)
  "描述 函数的详细信息的字符串 可有可无"
  (interactive)
  (let (localVar1 localVar2 …)
    ; do something here …
    ; …
    ; last expression is returned
  )
)

 

你可能感兴趣的:(c,String,function,list,语言,lisp)