Lisp-arithmetic-operators
提供:Dev Guides
LISP-算術演算子
次の表は、LISPでサポートされているすべての算術演算子を示しています。 変数 A が10を保持し、変数 B が20を保持すると仮定します-
Operator | Description | Example |
---|---|---|
+ | Adds two operands | (+A B) will give 30 |
- | Subtracts second operand from the first | (- A B) will give -10 |
* | Multiplies both operands | (* A B) will give 200 |
/ | Divides numerator by de-numerator | (/B A) will give 2 |
mod,rem | Modulus Operator and remainder of after an integer division | (mod B A )will give 0 |
incf | Increments operator increases integer value by the second argument specified | (incf A 3) will give 13 |
decf | Decrements operator decreases integer value by the second argument specified | (decf A 4) will give 9 |
例
main.lispという名前の新しいソースコードファイルを作成し、次のコードを入力します。
(setq a 10)
(setq b 20)
(format t "~% A + B = ~d" (+ a b))
(format t "~% A - B = ~d" (- a b))
(format t "~% A x B = ~d" (* a b))
(format t "~% B/A = ~d" (/b a))
(format t "~% Increment A by 3 = ~d" (incf a 3))
(format t "~% Decrement A by 4 = ~d" (decf a 4))
実行ボタンをクリックするか、Ctrl + Eを入力すると、LISPはすぐに実行し、返される結果は-
A + B = 30
A - B = -10
A x B = 200
B/A = 2
Increment A by 3 = 13
Decrement A by 4 = 9