When executing the below code in sbcl repl, i'm getting the 'undefined variable' warning for variables test-cases, n. I've gone through similar questions on the forum and the warning appears to occur if a variable is setf/setq'ed without defining first. But i have defined those variables using defparameter but still getting the warning.
One thing i noticed is, if i don't reference the variables in the format statement, warning is not occuring. I've tried using defvar as well. but it is still throwing the warning. can someone help me understand why the warning is thrown when used in a statment even if the variable is defined?
(defun main ()
(defvar test-cases 10)
(defvar l 12)
(defvar n 13)
(format t "~a ~a ~a" test-cases l n))
; in: DEFUN MAIN
; (FORMAT T "~a ~a ~a" TEST-CASES L N)
;
; caught WARNING:
; undefined variable: N
;
; caught WARNING:
; undefined variable: TEST-CASES
;
; compilation unit finished
; Undefined variables:
; N TEST-CASES
; caught 2 WARNING conditions
WARNING: redefining COMMON-LISP-USER::MAIN in DEFUN
DEFVARis for global variables defined on the top-level. UseLETto define local variables. See Practical Common Lisp chapter 6. Variables - jkiiski