0
0

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 5 years have passed since last update.

AutoLISP 比較演算関数と条件関数の使い方

Posted at

比較演算関数と条件関数リファレンス(公式ヘルプ)

値が等しいか調べる =

(= 1 1)
;; -> T
(= "a" "a")
;; -> T
(= 4 (+ 1 2))
;; -> nil
(= "a" "A")
;; -> nil

値が等しくないかか調べる /=

(/= 1 1)
;; -> nil
(/= "a" "a")
;; -> nil
(/= 4 (+ 1 2))
;; -> T
(/= "a" "A")
;; -> T

数値の大きさを比べる < <= > >=

(< 1 1)
;; -> nil
(< 1 2)
;; -> T
(< 2 1)
;; -> nil
(< "a" "a")
;; -> nil
(< "a" "A")
;; -> nil

(<= 1 1)
;; -> T
(<= 1 2)
;; -> T
(<= 2 1)
;; -> nil
(<= "a" "a")
;; -> T
(<= "a" "A")
;; -> nil

(> 1 1)
;; -> nil
(> 1 2)
;; -> nil
(> 2 1)
;; -> T
(> "a" "a")
;; -> nil
(> "a" "A")
;; -> T
(>= 1 1)
;; -> T

(>= 1 2)
;; -> nil
(>= 2 1)
;; -> T
(>= "a" "a")
;; -> T
(>= "a" "A")
;; -> T

AND(論理積)を返す and

(and T T)
;; -> T
(and T nil)
;; -> nil
(and nil nil)
;; -> nil

ビット方式の汎用ブール演算 boole

(boole 1 1 1)
;; -> 1
(boole 6 1 1)
;; -> 0
(boole 7 1 1)
;; -> 1
(boole 8 1 1)
;; -> -2

多分岐条件関数(swich文) cond

(setq val 1)
(cond
    ((= 1 val) 1)
    ((= 2 val) 2)
    ((= 3 val) 3)
)
;; -> 1

2つの式が同一物かどうかを調べる eq

(eq 1 1)
;; -> T
(eq "a" "a")
;; -> T
(eq (+ 1 1) (/ 4 2))
;; -> T
(eq (type 1) (type 2))
;; -> T
(eq (= 1 1) (numberp 2))
;; -> T
(eq 'a 'A)
;; -> T

2つの式の評価結果が等しいかどうかを調べる equal

(equal 1 1)
;; -> T
(equal "a" "a")
;; -> T
(equal (+ 1 1) (/ 4 2))
;; -> T
(equal (type 1) (type 2))
;; -> T
(equal (= 1 1) (numberp 2))
;; -> T
(equal 'a 'A)
;; -> T

条件に応じて式を評価(if文) if

(setq val 1)
if (= 1 val)
    1 ;_T(true) のとき
    0 ;_nil(false) のとき
)
;; -> 1

(setq val 9)
if (= 1 val)
    1 ;_T(true) のとき
    0 ;_nil(false) のとき
)
;; -> 0

OR(論理和)を返す or

(or T T)
;; -> T
(or T nil)
;; -> T
(or nil nil)
;; -> nil

指定された回数繰り返す repeat

(repeat 5
    (print "Hello")
)
;; -> "Hello"
;;    "Hello"
;;    "Hello"
;;    "Hello"
;;    "Hello"

(setq val 0)
(repeat 10
    (setq val (1+ val))
)
;; -> val = 10

条件がTの間繰り返す while

(setq val 0)
(while(< val 10)
    (setq val (1+ val))
)
;; -> val = 11

;; 無限ループ
(while T
    ・・・
)
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?