Skip to content

_global

bergsma edited this page Sep 26, 2014 · 5 revisions

#global

###Define global scope or make a local variable global.

Syntax

status = global[  variable ] ;

Arguments

  1. list variable(optional)

If the variable is local, it is made global, otherwise it is unchanged.

Return Value

str status
  • $ACKNOWLEDGE : The variable was made global, or the program is switched to global scope.

The STATUS variable is set to $ACKNOWLEDGE

str status
  • $ACKNOWLEDGE : The variable was made global, or the program is switched to global scope.

The STATUS variable is set to $ACKNOWLEDGE

Exceptions

  • %ARGUMENT: Invalid arguments. Usage: status = global[ variable ] ;

  • %IDENTIFIER: 'variable' argument is not a valid identifier, literal, or reference

  • %UNDEFINED: Variable does not exist

Description

In global scope, variables defined will be global in scope.

In local scope, variables defined will be local in scope.

If a variable is local, it can be redefined in global scope. Any previous global variable is overwritten and the local definition no longer exists.

If a variable is global, it can be redefined in local scope. Any previous local variable is overwritten and the global definition no longer exists.

Global variables (and methods) created by the concept instance have a super-global scope, they are visible to all instances providing the instance has not already defined the variable in local or global scope. If the instance un-defines its own global and local copies of the variable, then the variable defined in the concept instance becomes visible. Local variables created in the concept instance are not accessible by other instances and visa versa.

A common mistake when trying to create a local variable over top of a global variable is not to typedef it. For example:

	// Define global scope
	global ;

	// Define a global variable (we didn't use a typedef, so the type is 'list'
	a = 100 ;

	// Define local scope
	local ;

	// The following statement simply overwrites the global variable 'a'
	a = 101 ;

	// But the next statement creates a new local variable because it was typedef'd
	int a = 1 ;

Examples

puts "Create an example for the function 'global'" ;

Related Links

local

Clone this wiki locally