How do I test whether a variable is defined before referencing it?

前端 未结 3 1169
庸人自扰
庸人自扰 2021-02-09 15:04

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

3条回答
  •  借酒劲吻你
    2021-02-09 15:24

    To back up a bit, the problem with a defined? function is that if you write

    (defined? debug-level)
    

    Scheme will attempt to evaluate debug-level, which of course is an error since it is not defined. Such a form would have to be implemented internally by the compiler/interpreter as a special case.

    Such a special form is not part of the R5RS standard (unless I missed it, please double-check). So with regard to R5RS schemes you are out of luck unless you find a Scheme that implements this as a non-standard extension.

提交回复
热议问题