2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AutoLISP 関数処理関数の使い方

Last updated at Posted at 2020-03-06

関数処理関数リファレンス(公式ヘルプ)

引数のリストを指定された関数に渡す 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
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?