The Comparison Operators , /, <, <=, >, >=

← Prev | ↑ Chapter | Next → | Index | Symbols

The Comparison Operators , /, <, <=, >, >=

The six comparison operators =, /=, <, <=, >, and >= are documented here, next to eq and equal, because they are general comparison predicates: they compare numbers and strings, not numbers only. (Chapter 8, "Numbers", carries a forward-reference to this location.) The equality pair = / /= accepts arguments of any type; the ordering operators < <= > >= are restricted to numbers and strings, with nil as a distinguished smallest value.

The rules below were measured, not assumed: the probe autolisp-front-end/tests/scenarios/language/comparison-operators-probe.lsp (40 argument cases × 6 operators = 240 observations) was run on AutoCAD 2022 (French, Windows), BricsCAD V25 (Windows) and BricsCAD V26 (macOS), 2026-09-25. The two BricsCAD builds are identical; AutoCAD and BricsCAD agree on 237 of the 240 observations, and the three that differ are listed under Vendor divergence below. (Earlier drafts of this section stated a type error for (= 1 "1") and a "bottom propagation" rule for nil; both were unverified and are contradicted by both vendors.)

Shared rules

  • Arity: at least one argument. No argument is an error (AutoCAD: "nombre d'arguments insuffisants"; BricsCAD: "too few / too many arguments"). One argument returns T, whatever its type — no type check: (< 'a) => T, (= nil) => T.
  • Chaining: with several arguments, each argument is compared with the one to its right, left to right, and evaluation stops at the first pair that is false; the result is T iff every pair holds. This holds for /= too: (/= 1 2 1) => T (1/2 and 2/1 both differ) — /= is not "all arguments distinct".
  • Numbers compare by value across the integer/real tower — (= 1 1.0) => T — under the coercion rules of "Normative Rules: Number Tower and Division" (chapter 3 / chapter 8).
  • Strings compare by content, case-sensitively, and the ordering operators order them lexicographically by character code point, left to right, a prefix before its extensions: (< "B" "a") => T, (< "ab" "abc") => T, (< "" "a") => T.

Equality: = and /=

  • Accept arguments of any type and never signal a type error.
  • Numbers by value, strings by content; any other pair compares by identity (eq): (= 'a 'a) => T, (= T T) => T, (= nil nil) => T, the same list object twice => T, two equal but distinct lists => nil.
  • A number against a string is simply unequal: (= 1 "1") => nil, (/= 1 "1") => T.

Ordering: <, <=, >, >=

  • A pair of two numbers, or of two strings, compares as above.
  • nil is the smallest value: it is below every number, string, symbol or list, and equal to itself. So (< nil 1) => T, (> "a" nil) => T, (> 'a nil) => T, (<= nil nil) => T, (< nil nil) => nil, (< 1 nil) => nil. The loop-guard idiom (while (<= 48 (car chars) 57) ...) stops at the end of the list because (<= 48 nil) is false.
  • Any other pair of non-nil arguments — a number against a string, a symbol, T, a list — signals a type error naming the pair (AutoCAD: "type d'argument de comparaison incorrect: 1 \"a\""; BricsCAD: "bad argument type <\"a\"> ; expected <NUMBER>"). Because the chain stops at its first false pair, an incompatible pair after a false one is never reached: (> nil 1 "a") => nil, but (< nil 1 "a") signals (nil < 1 holds, so 1 vs "a" is compared).

    (< 1 nil)        => nil    ; nil is below 1
    (< nil 1)        => T
    (< "abc" nil)    => nil
    (>= 1 nil)       => T
    (<= nil nil)     => T
    (< 1 "a")        -> TYPE ERROR
    (< 'a 'b)        -> TYPE ERROR
    (< 1 "a" nil)    -> TYPE ERROR  ; 1 vs "a" is the first pair
    (> nil 1 "a")    => nil         ; stops at nil > 1 (AutoCAD; see below)
    

Vendor divergence

Three probe observations differ between the vendors; this specification adopts AutoCAD (it stops at the first false pair, and treats >= like >):

expression AutoCAD 2022 BricsCAD V25 / V26
(>= 'a nil) T type error
(> nil 1 "a") nil type error
(>= nil 1 "a") nil type error

BricsCAD raises the type error of every incompatible pair in the chain, even past a false one, and rejects a non-number, non-string argument to the left of nil under >= (but not under >). This is a resolved divergence (chapter 25, case 2): see the *** clautolisp notes under > and >=.

See also "Normative Rules: Equality Predicates" (chapter 3), which states these operators alongside eq~/~equal.