Adam Lee
Adam Lee

Reputation: 586

Unable to check whether a boolean is true?

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?

Upvotes: 0

Views: 809

Answers (1)

Martin Půda
Martin Půda

Reputation: 7568

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))

Upvotes: 4

Related Questions