Testing for the definedness of a variable in Scheme -
besides regular definitions (define variable value)
scheme allows uninitialized definitions (define variable)
, when variable bound value later on aid of set!
.
are there procedures allowing test whether symbol defined (not initialized) variable? (defined? 'variable)
should return #t
if variable
defined , #f
otherwise?
the form (define var)
non-standard extension.
according r5rs define
has 1 of following forms:
(define <variable> <expression>) (define (<variable> <formals>) <body>) (define (<variable> . <formal>) <body>)
as far can tell same goes r6rs , r7rs.
most (define foo)
expands (define foo the-undefined-value)
in implementation. means can use (if (eq? foo the-undefined-value) ...) test whether
foo` has been initialized or not.
http://www.schemers.org/documents/standards/r5rs/html/r5rs-z-h-8.html#%_idx_190
update:
i checked r6rs , says:
(define <variable> <unspecified>) <unspecified> side-effect-free expression returning unspecified value.
consider
(define foo) (define bar)
it implementor whether same unspecified value bound both foo
, bar
.
try program:
(define unspecified) (define unspecified1) (eq? unspecified unspecified1)
if program evaluates #t
can write initialized?
predicate this:
(define unspecified) (define (initialized? x) (not (eq? x unspecified))) (define test) (initialized? test) (set! test 42) (initialized? test)
Comments
Post a Comment