Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Scilab > Variables > isglobal

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.

  • If x is defined in the global space but not in the local one, isglobal("x") will return %F (as isdef("x")).
  • If varname is a text not corresponding to the name of any variable, no error occurs and %F is returned.
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 >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:23:20 CET 2022