Home > Blockchain >  Unreachable code within Cond recursive function -- why?
Unreachable code within Cond recursive function -- why?

Time:11-09

With my recursive function, I have a cond with a fail conditon.

When the concequence of the fail condition is nil, everything works fine.

But when I try to change the concequence of the fail condition to something else:

(defun rec ()
  (cond ((null t) (format t ....))
        ....)

it says that the (format t....) function is unreachable... why?

CodePudding user response:

In Common Lisp, t is a boolean constant that means “true”. So, the expression (null t) checks if t is the empty list and this is obviously always false. So the compiler is smart enough to infer that the code (format ... is never reached and does not compile it.

Errors like this arise sometimes when one forgets the meaning of t, and tries to use it as a variable.

  • Related