File: global.g

package info (click to toggle)
gap 4r4p12-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 29,584 kB
  • ctags: 7,113
  • sloc: ansic: 98,786; sh: 3,299; perl: 2,263; makefile: 498; asm: 63; awk: 6
file content (135 lines) | stat: -rw-r--r-- 4,568 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#############################################################################
##
#W  global.g                    GAP library                      Steve Linton
##
#H  @(#)$Id: global.g,v 4.10 2002/04/15 10:04:42 sal Exp $
##
#Y  Copyright (C)  1996,  Lehrstuhl D fuer Mathematik,  RWTH Aachen,  Germany
#Y  (C) 1998 School Math and Comp. Sci., University of St.  Andrews, Scotland
#Y  Copyright (C) 2002 The GAP Group
##
##
##  This file contains the first stage of the "public" interface to
##  the global variable namespace, allowing globals to be accessed and
##  set by name.
##
##  This is defined in two stages. This file defines "capitalized" versions
##  of the functions which do not use Info or other niceties and are not
##  set up with InstallGlobalFunction. This can thus be read early, and
##  the functions it defines can be used to define functions used to read
##  more of the library.
##
##  The global.gd and global.gi stages will install the really "public"
##  functions and can be read later (once Info, DeclareGlobalFunction,
##  etc are there)
##
Revision.global_g :=
    "@(#)$Id: global.g,v 4.10 2002/04/15 10:04:42 sal Exp $";


#############################################################################
##
#F  VALUE_GLOBAL ( <name> ) .  . . . . . . . . . .access a global by its name
## 
##  VALUE_GLOBAL ( <name> ) returns the value currently bound to the global
##  variable named by the string <name>. An error is raised if no value
##  is currently bound
##

VALUE_GLOBAL := VAL_GVAR;


#############################################################################
##
#F  ISBOUND_GLOBAL ( <name> ) .  . . . check if a global is bound by its name
## 
##  ISBOUND_GLOBAL ( <name> ) returns true if a value currently bound
##  to the global variable named by the string <name> and false otherwise
##

ISBOUND_GLOBAL := ISB_GVAR;


#############################################################################
##
#F  UNBIND_GLOBAL ( <name> ) .  . . . . . . . . .unbind a global  by its name
## 
##  UNBIND_GLOBAL ( <name> ) removes any value currently bound
##  to the global variable named by the string <name>. Nothing is returned.
##
##  The global variable named by <name> must be writable,
##  otherwise an error is raised.
##

UNBIND_GLOBAL := UNB_GVAR;

#############################################################################
##
#F  IS_READ_ONLY_GLOBAL ( <name> ) determine if a global variable is read-only
##
##  IS_READ_ONLY_GLOBAL ( <name> ) returns true if the global variable
##  named by the string <name> is read-only and false otherwise (the default)
##

IS_READ_ONLY_GLOBAL := IsReadOnlyGVar;

#############################################################################
##
#F  MAKE_READ_ONLY_GLOBAL ( <name> ) . . . . make a global variable read-only
##
##  MAKE_READ_ONLY_GLOBAL ( <name> ) marks the global variable named
##  by the string <name> as read-only. 
##

MAKE_READ_ONLY_GLOBAL := MakeReadOnlyGVar;

#############################################################################
##
#F  MAKE_READ_WRITE_GLOBAL ( <name> ) . . .make a global variable read-write
##
##  MAKE_READ_WRITE_GLOBAL ( <name> ) marks the global variable named
##  by the string <name> as read-write
##

MAKE_READ_WRITE_GLOBAL := MakeReadWriteGVar;

#############################################################################
##
#V  REREADING                set to true inside a Reread, changes much
##                           behaviour
##

REREADING := false;
MAKE_READ_ONLY_GLOBAL("REREADING");


#############################################################################
##
#F  BIND_GLOBAL ( <name>, <val> ) . . . . . .sets a global variable 'safely'
##
##  BIND_GLOBAL ( <name>, <val> ) sets the global variable named by
##  the string <name> to the value <val>, provided it was previously
##  unbound, and makes it read-only. This is intended to be the normal
##  way to create and set "official" global variable (such as
##  Operations and Categories)
##
  
BIND_GLOBAL := function( name, val)
    if not REREADING and ISBOUND_GLOBAL( name ) then
        if (IS_READ_ONLY_GLOBAL(name)) then
            Error("BIND_GLOBAL: variable `", name, "' must be unbound");
        else
            Print("#W BIND_GLOBAL: variable `", name,"' already has a value\n");
        fi;
    fi;
    ASS_GVAR(name, val);
    MAKE_READ_ONLY_GLOBAL(name);
    return val;
end;

#############################################################################
##
#E  global.g . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here