I would like to be able to test whether a variable is defined, prior to accessing it.
I like to have a global that specifies a "debug level". If debug level is 0, no extra output is given. When greater than 1, debug output is given, with more verbosity at greater numbers.
I also would like to set it up so that the procedures would run, and assume a level 0, if I had not gotten around to defining it. Something like: (where defined?
is the magic I don't know how to do?
(if (and (defined? debug-level) (> debug-level 1))
(diplay "Some debugging info"))
I have looked through the summary of forms in The Scheme Programming Language, 4th Edition. The only one that I saw as a possibility was identifier?
. It did not work.
I'm using SISC 1.16.6 (claims R5RS compliance) and Chez Petite Scheme v8 (claims R6RS compliance)
EDIT I tried wrapping eval
with a guard
like:
(guard (x (else #f)) (eval 'debug-level))
Since 'debug-level
is quoted it can be evaluated and passed to eval
. Then when eval
tries to evaluate it, an error would happen, which I hoped guard
would catch. It didn't.
EDIT 2 I realized that I wanted to wrap the debug tracing into a seperate procedure and that the file that defines that procedure can also define debug-level
with a default of 0. The reasons for using a seperate procedure are to lower the number of lines in the procedures that do work and also to allow the redirection of debug output if needed.