elispの真偽値関連の知識
[履歴] [最終更新] (2016/01/09 14:17:57)

概要

以下はすべてEshell上での実行結果例です。

elispの偽はnilのみ

elispにおいて、偽はnil (および「nil」と同等の概念である「()」) のみです。他のもの、例えばt,"",[],0,1などはすべて真です。

偽の反転

$ (not nil)
t
$ (not ())
t

真の反転の反転

$ (not (not t))
t
$ (not (not ""))
t
$ (not (not 0))
t
$ (not (not []))
t
$ (not (not 1))
t

数値の比較

等しい

$ (= 2 2)
t
$ (= 2 2.0)
t

等しくない

$ (/= 1 2)
t

不等号

$ (< 1 2)
t
$ (> 2 1)
t
$ (<= 2 2)
t
$ (>= 2 2)
t
$ (and (<= 1 2) (<= 2 3))
t

equalとeq

equal:値が同じ

$ (equal [10] [10])
t

eq:参照先が同じ

$ (not (eq [10] [10]))
t
$ (progn ;複数のフォームを一纏めにするために使用され、最後に評価した結果を返します
  (setq var1 [10])
  (setq var2 var1)
  (eq var1 var2))
t
関連ページ