Scilab 6.0.1
Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
isglobal
checks if a local variable has a global counterpart
Syntax
t = isglobal(varname)
Arguments
- varname
text: name of any single local variable. This is not the variable itself (that provides its content), but its name.
- t
a boolean
Description
isglobal("x")
returns %T
if the variable
x
is defined locally and points to a global counterpart. It returns
%F
otherwise.
|
The list of all variables defined in the global space (but not necessarily in the local
one) can be retrieved with who("global") . |
Examples
Example #1 with a predefined global variable:
mprintf("%s\n", who("global")) // demolist has a global definition... isdef("demolist") // %F: ... but no local one (not yet) demolist(1) // => "Undefined variable" isglobal("demolist") // => %F, since it has no local definition global demolist // We define a local demolist and make it pointing to the existing global one demolist($,:) // Here is the last row of the existing global content isglobal("demolist") // => now %T
--> mprintf("%s\n", who("global")) // demolist has a global definition... %helps %modalWarning %toolboxes %toolboxes_dir demolist --> isdef("demolist") // ... but no local one (not yet) ans = F --> demolist(1) // So: => "Undefined variable" Undefined variable: demolist --> isglobal("demolist") // => %F, since it has no local definition ans = F --> global demolist // We define a local demolist and make it pointing to the existing global one --> demolist($,:) // Here is the last row of the existing global content ans = !Xcos SCI\modules\xcos\demos\xcos.dem.gateway.sce ! --> isglobal("demolist") // => now %T ans = T
Example #2 with a custom variable:
// In the list hereabove, "abc" does not exist. Let's create it locally and globally: global abc // initialized with [] isdef("abc") // => %T isglobal("abc") // => %T abc = %pi; // Writes simultaneously in the local AND global spaces clear abc // We delete the local definition, but not the global one abc // => "undefined variable" isglobal("abc") // => %F, since there is no longer any local alias global abc // We redefine abc connected to its global counterpart. What is it? abc
--> // In the list hereabove, "abc" does not exist. Let's create it locally and globally: --> global abc // initialized with [] --> isdef("abc") ans = T --> isglobal("abc") ans = T --> abc = %pi; // Writes simultaneously in the local AND global spaces --> clear abc // We delete the local definition, but not the global one --> abc // => "undefined variable" Undefined variable: abc --> isglobal("abc") // => %F, since without local alias ans = F --> global abc // We redefine abc connected to its global counterpart. What is it? --> abc abc = 3.1415927
See also
- global — Define global variable
- clearglobal — kills global variables
- who — listing of variables
- isdef — checks variable existence
Report an issue | ||
<< isdef | Variables | names >> |