prog::isGlobal
-- information
about reserved identifiersprog::isGlobal(
ident)
determines whether
the identifier ident
is used by the system.
prog::isGlobal(ident)
ident |
- | identifier to check |
prog::isGlobal
return TRUE
, if the given
identifier is used by the system, otherwise FALSE
.
prog::check
, anames
, type
, domtype
prog::isGlobal(
ident)
checks if the
identifier ident
is ``used by the system''. Here, ``used
by the system'' means that ident
is an environment
variable (e.g., PRETTYPRINT
), a system-wide
constant (e.g., PI
and
undefined
), an
option (for some function call, e.g., All
), or a system
function (such as sin
).Assume you would like to use some identifiers as options
for a new function you wrote. In this example, we will check the
elements of the list [All, Beta, Circle, D, eval, First]
for suitability. (Note that eval
would not be a good
choice, even if it was not a system function, because options should
start with a capital letter.)
We define a test function which is mapped to the list and returns FAIL
, if the tested object is not an
identifier, TRUE
, if the
identifier is used by the system and FALSE
otherwise:
>> reset(): LIST:= [All, Beta, Circle, D, eval, First]: map(LIST, X -> if domtype(X) <> DOM_IDENT then X = FAIL else X = prog::isGlobal(X) end_if)
[All = TRUE, Beta = FALSE, Circle = FALSE, D = FAIL, eval = FAIL, First = TRUE]
The identifiers All
and First
can be used as options because they have already been protected by the
system (actually, they are already used as options, which makes them a
good choice), the identifiers Beta
and Circle
are free and one must only take care that they have no value if they
will be used as options--they should be protected first. D
and
eval
have values and cannot be used as options.