;run elisp with C-x C-e
(+ 3 4)
;print message
(message "hi")
;print variable values
(message "this number is %d" 0)
;print string
(message "this string is %s" "jianghao")
;any expression
(message "what this variable ? %S " (list 1 2 3 4 5))
;Arithmetic Functions
(+ 4 5) ;9
(- 9 2) ;7
(- 9 2 3) ;4
(+ 4 5 (- 4 2)) ;11
(* 3 4) ;12
(* 2 3 2) ;12
(/ 2 4) ;0
(/ 2 4.0) ;0.5
(% 3 4) ;3
(expt 2 3);8
;t = ture nil = false
;;decimal number,must have a number after dot
;check expression is integer
(integerp 3.) ;t
;check expression is float
(floatp 3.) ;nil
(floatp 3.0) ;t
;Coventing String And number
(string-to-number "22")
(number-to-string 22)
;if
;false
(if nil "Oh Is ture" "false") ; false
(if () "Ture" "False") ;False
(if (list) "ture" "false") ;false
(if '() "One" "two") ;two
;ture
(if t "that`s ture" "you see")
(if 0 "Yes" "no")
(if [] "YU" "sorry") ; [] = 0
(if "" "Y" "N")
;elisp no boolean datatype just () and nil
(and t nil) ;&
(or t nil) ;|
;comparison functions
;number comparion
(< 3 5) ;less than
(> 1 2) ;great than
(<= 2 2) ;less or equal
(>= 1 9) ;greater or equal
(= 3 3) ;equal t
(= 1 1.0) ;equal t
(/= 2 2) ; not equal nil
;string comparion
(string-equal "YOU" "YOU") ;
;equal test datatype and values equal
(equal 1 1);t
(equal 1 1.0);t datattype not match
(equal "" "");
(equal '(1 2 3) '(1 2 3));comparion list
(not (= 3 4)) ; 3 not equal 4 t
(/= 2 4) ; /= compartion number only
(not (equal 1 3)) ; General way to test inequality
;;;; Global and Local Variables setq use to set variable
;;;; declared Global Variable
(setq f 7)
(message "as %d" f)
(setq a 1 b 3 c 4)
;;(let (‹var1› ‹var2› …) ‹body›) body last expressions is returnd
(let (a b)
(setq a 3)
(setq b 4)
(+ a b)
)
;;anothor (let ((‹var1› ‹val1›) (‹var2› ‹val2›) …) ‹body›)
(let ((a 3) (b 4))
(+ a b)
)
;;;; block of Expressions
(progn (message "hi a") (message "hi b"))
(if nil
(progn ;ture
(message "that ture")
)
(progn ;false
(message "false")
)
)
;;;; while
(setq i 0)
(while (< i 4)
(print (format "Num %d" i))
(setq i (+ 1 i))
)
;;Iteration
(let ((x 32))
(while (< x 127)
(ucs-insert x)
(setq x (+ x 1))))
;;;; Defining a Function
;; (defun ‹function name› (‹param1› ‹param2› …) "‹doc string›" ‹body›)
(defun yay ()
"Insert “Yay!” at cursor position."
(interactive)
(insert "/**\n * @param\n * @return\n */"))
(defun test (args)
"Prints the argument"
(interactive "p")
(message "You args is :%d " args))
;;
(defun se(start end)
"print star and end"
(interactive "r")
(message "Region begin at : %d ,end at : %d" start end)
)
;;;; Interactive 交互的意思
;; (interactive "p") p表示 数字前缓参量
;; r 表示位点
;; b 表示一个已经存在缓冲区的名字
;; f 表示一个已经存在的文件名字
;;
(defun see(buffer)
"buffer area print"
(interactive "b")
(message "buffer name is : %s" buffer)
)
;; 字符串连接
(concat "a" "b")
初步学习elisp
最新推荐文章于 2024-08-22 11:08:29 发布