0

I am trying to check whether a boolean variable (boolVariable) is True (T) using the following code:

(defvar boolVariable T)

(if (= boolVariable T)
    (print 'TRUE)
)

However, I get the following error:

  • =: T is not a number

This seems strange, considering that I thought that you can check whether variables equal booleans in Lisp?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Adam Lee
  • 436
  • 1
  • 14
  • 49
  • Note that the standard readtable upcases all symbols, so your `boolVariable` is actually `BOOLVARIABLE`. In Lisp the convention is to use kebab-case. – Svante Feb 03 '22 at 10:10

1 Answers1

4

Common Lisp's = compares only numbers and neither t nor boolVariable is number.

There are some other equality predicates like eq, eql, equal or equalp, but in this case, you can just use value of bool-variable (renamed in kebab-case):

(defvar bool-variable t)
(if bool-variable (print 'TRUE))

If with only then-form can be also replaced with when:

(defvar bool-variable t)
(when bool-variable (print 'TRUE))
Martin Půda
  • 7,353
  • 2
  • 6
  • 13