[slang-users] Implicit variable declarations

John E. Davis davis at space.mit.edu
Tue Mar 7 11:34:43 EST 2006


Michael Noble <mnoble at space.mit.edu> wrote:
>> variable x = [1:100:1];
>> newvar = @x;
>> is_defined("newvar");
>
>Then I believe this is a namespace issue.

Right.  Unless a namespace prefix is specified, `is_defined` searches
the "Global" namespace.  Variables that are automatically declared are
placed in the static namespace, which may be anonymous as in your
case.  The `is_defined` function will not search such namespaces.  If
you want to search the current namespace, which may be an
anonymous one, then use the `_apropos` function, e.g.,

   names = _apropos (current_namespace (), "^newvar$", 0xFF);

Also you might consider using __get_reference:

   if (NULL != __get_reference ("newvar"))
     {
       % newvar is defined
         .
	 .
     }

Thanks,
--John




More information about the slang-users-l mailing list