📜  LISP 中的比较运算符

📅  最后修改于: 2022-05-13 01:55:31.903000             🧑  作者: Mango

LISP 中的比较运算符

在这篇文章中,我们将讨论在LISP运算符。这些运算符用于通过采用两个或多个操作数来比较数字。

注意:这仅适用于数字,

不同的比较运算符是:

OperatorSyntaxNameDescription
== operand1 operand2equal toThis operator checks if the values of the operands are all equal or not, if yes, will return T(True) otherwise NIL
/=/= operand1 operand2not equal toThis operator checks if the values of the operands are not equal, if yes, will return NIL otherwise T (True)
>> operand1 operand2greater thanThis operator checks if the values of the operand 1 are greater than operand 2, if yes then it returns True, otherwise NIL
<less thanThis operator checks if the values of the operand 1 are less than operand 2, if yes then it returns True, otherwise NIL
>=>= operand1 operand2greater than or equal toThis operator checks if the values of the operand 1 are greater than or equal to  operand 2, if yes then it returns True, otherwise NIL
<=<= operand1 operand2less than or equal toThis operator checks if the values of the operand 1 are less than or equal to  operand 2, if yes then it returns True, otherwise NIL
maxmax operand1 operand2maximum numberThis operator returns the maximum value.
minmin operand1 operand2minimum numberThis operator returns the minimum value.

例如:LISP程序上比较运算符演示。

Lisp
;set value 1 to 100
; set value 2 to 200
(setq val1 100)
(setq val2 200)
  
;check val1 is equal to val2 or not
(print (= val1 val2))
  
;check val1 is not equal to val2 or not
(print (/= val1 val2))
  
;check val1 is greater than val2 or not
(print (> val1 val2))
  
;check val1 is less than val2 or not
(print (< val1 val2))
  
;check val1 is greater than or equal to val2 or not
(print (>= val1 val2))
  
;check val1 is less than or equal to val2 or not
(print (<= val1 val2))
  
;get maximum number among val1 and val2
(print (max val1 val2))
  
;get minimum number among val1 and val2
(print (min val1 val2))


Lisp
;set value 1 to 20
; set value 2 to 70
(setq val1 20)
(setq val2 70)
  
;check val1 is equal to val2 or not
(print (= val1 val2))
  
;check val1 is not equal to val2 or not
(print (/= val1 val2))
  
;check val1 is greater than val2 or not
(print (> val1 val2))
  
;check val1 is less than val2 or not
(print (< val1 val2))
  
;check val1 is greater than or equal to val2 or not
(print (>= val1 val2))
  
;check val1 is less than or equal to val2 or not
(print (<= val1 val2))
  
;get maximum number among val1 and val2
(print (max val1 val2))
  
;get minimum number among val1 and val2
(print (min val1 val2))


Lisp
;set value 1 to 50
; set value 2 to 50
(setq val1 50)
(setq val2 50)
  
;check val1 is equal to val2 or not
(print (= val1 val2))
  
;check val1 is not equal to val2 or not
(print (/= val1 val2))
  
;check val1 is greater than val2 or not
(print (> val1 val2))
  
;check val1 is less than val2 or not
(print (< val1 val2))
  
;check val1 is greater than or equal to val2 or not
(print (>= val1 val2))
  
;check val1 is less than or equal to val2 or not
(print (<= val1 val2))
  
;get maximum number among val1 and val2
(print (max val1 val2))
  
;get minimum number among val1 and val2
(print (min val1 val2))


输出:



NIL  
T  
NIL  
T  
NIL  
T  
200  
100 

示例 2:

Lisp

;set value 1 to 20
; set value 2 to 70
(setq val1 20)
(setq val2 70)
  
;check val1 is equal to val2 or not
(print (= val1 val2))
  
;check val1 is not equal to val2 or not
(print (/= val1 val2))
  
;check val1 is greater than val2 or not
(print (> val1 val2))
  
;check val1 is less than val2 or not
(print (< val1 val2))
  
;check val1 is greater than or equal to val2 or not
(print (>= val1 val2))
  
;check val1 is less than or equal to val2 or not
(print (<= val1 val2))
  
;get maximum number among val1 and val2
(print (max val1 val2))
  
;get minimum number among val1 and val2
(print (min val1 val2))

输出:

NIL  
T  
NIL  
T  
NIL  
T  
70  
20 

示例 3: LISP 程序操作数具有相同的数字。

Lisp

;set value 1 to 50
; set value 2 to 50
(setq val1 50)
(setq val2 50)
  
;check val1 is equal to val2 or not
(print (= val1 val2))
  
;check val1 is not equal to val2 or not
(print (/= val1 val2))
  
;check val1 is greater than val2 or not
(print (> val1 val2))
  
;check val1 is less than val2 or not
(print (< val1 val2))
  
;check val1 is greater than or equal to val2 or not
(print (>= val1 val2))
  
;check val1 is less than or equal to val2 or not
(print (<= val1 val2))
  
;get maximum number among val1 and val2
(print (max val1 val2))
  
;get minimum number among val1 and val2
(print (min val1 val2))

输出:

T  
NIL  
NIL  
NIL  
T  
T  
50  
50