Lisp-logical-operators
提供:Dev Guides
LISP-論理演算子
Common LISPは、ブール値を操作する* and、or、、 *not の3つの論理演算子を提供します。 A の値がnilで、 B の値が5であると仮定します-
Operator | Description | Example |
---|---|---|
and | It takes any number of arguments. The arguments are evaluated left to right. If all arguments evaluate to non-nil, then the value of the last argument is returned. Otherwise nil is returned. | (and A B) will return NIL. |
or | It takes any number of arguments. The arguments are evaluated left to right until one evaluates to non-nil, in such case the argument value is returned, otherwise it returns nil. | (or A B) will return 5. |
not | It takes one argument and returns t *if the argument evaluates to nil.* | (not A) will return T. |
例
main.lispという名前の新しいソースコードファイルを作成し、次のコードを入力します。
実行ボタンをクリックするか、Ctrl + Eを入力すると、LISPはすぐに実行し、返される結果は-
論理演算はブール値で機能し、2番目に、数値ゼロとNILは同じではないことに注意してください。