引数のリストを指定された関数に渡す apply
(apply '+ '(1 2 3 4 5))
;; -> 15
(apply 'strcat '("a" "b" "c" "d" "e"))
;; -> "abcde"
(apply 'list '(1 2 3 4 5))
;; -> (1 2 3 4 5)
関数を定義する defun
;; 足し算をする関数を定義
(defun add (a b /)
(+ a b)
)
(add 1 2)
;; -> 3
;; タンジェント求める関数を定義
(defun tan (x)
(/ (sin x) (cos x))
)
(tan (/ pi 4))
;; -> 1.0
AutoLISP 式として評価した結果を返す eval
(eval "car")
;; -> "car"
((eval car) '(1 2 3 4 5))
;; -> 1
((eval (read "car")) '(1 2 3 4 5))
;; -> 1
匿名の関数を定義する lambda
;; 2乗する匿名関数をシンボル(変数) f に格納
(setq f (lambda(x) (* x x)))
;; -> #<USUBR @0000029296274f48 -lambda->
(f 2)
;; -> 4
各式を順に評価して最後の式の値を返す progn
(if t
(setq a '(1 2 3))
(setq b (apply '+ a))
)
;; -> b = nil
(if t
(progn
(setq a '(1 2 3))
(setq b (apply '+ a))
)
)
;; -> b = 6