Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

136

137

138

139

140

141

142

143

144

145

146

147

""" 

List of assigned names in GAP 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.assigned_names import KEYWORDS, GLOBALS, FUNCTIONS 

sage: 'fi' in KEYWORDS 

True 

sage: 'ZassenhausIntersection' in GLOBALS 

True 

sage: 'SubdirectProduct' in FUNCTIONS 

True 

""" 

 

############################################################################### 

# Copyright (C) 2016, Volker Braun <vbraun.name@gmail.com> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at your option) any later version. 

# http://www.gnu.org/licenses/ 

############################################################################### 

 

 

from six.moves import cPickle 

import string 

from sage.libs.gap.libgap import libgap 

from sage.libs.gap.saved_workspace import workspace 

 

 

NamesGVars = libgap.function_factory('NamesGVars') 

Filtered =libgap.function_factory('Filtered') 

ValueGlobal = libgap.function_factory('ValueGlobal') 

IsBoundGlobal = libgap.function_factory('IsBoundGlobal') 

IsFunction = libgap.function_factory('IsFunction') 

IsDocumentedWord = libgap.function_factory('IsDocumentedWord') 

 

 

def load_or_compute(name, function): 

""" 

Helper to load a cached value or compute it 

 

INPUT: 

 

- ``name`` -- string. Part of the cache filename 

 

- ``function`` -- function. To compute the value if not cached. 

 

OUTPUT: 

 

The value of ``function``, possibly cached. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.assigned_names import GLOBALS 

sage: len(GLOBALS) > 1000 # indirect doctest 

True 

sage: from sage.libs.gap.saved_workspace import workspace 

sage: workspace(name='globals') 

('...', True) 

""" 

filename, up_to_date = workspace(name=name) 

if up_to_date: 

with open(filename, 'rb') as f: 

return cPickle.load(f) 

else: 

value = function() 

from sage.misc.temporary_file import atomic_write 

with atomic_write(filename) as f: 

cPickle.dump(value, f) 

return value 

 

 

def list_keywords(): 

""" 

Return the GAP reserved keywords 

 

OUTPUT: 

 

Tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.assigned_names import KEYWORDS 

sage: 'fi' in KEYWORDS # indirect doctest 

True 

""" 

keywords = libgap.get_global('GAPInfo')['Keywords'].sage() 

return tuple(sorted(keywords)) 

 

 

KEYWORDS = list_keywords() 

 

 

def list_globals(): 

""" 

Return the GAP reserved keywords 

 

OUTPUT: 

 

Tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.assigned_names import GLOBALS 

sage: 'ZassenhausIntersection' in GLOBALS # indirect doctest 

True 

""" 

gvars = set( 

name.sage() for name in NamesGVars() 

if IsBoundGlobal(name) 

) 

gvars.difference_update(KEYWORDS) 

return tuple(sorted(gvars)) 

 

 

GLOBALS = load_or_compute('globals', list_globals) 

 

 

def list_functions(): 

""" 

Return the GAP documented global functions 

 

OUTPUT: 

 

Tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.libs.gap.assigned_names import FUNCTIONS 

sage: 'IsBound' in FUNCTIONS # is a keyword 

False 

sage: 'SubdirectProduct' in FUNCTIONS # indirect doctest 

True 

""" 

fnames = set(GLOBALS).difference(KEYWORDS) 

documented = Filtered(list(fnames), IsDocumentedWord) 

return tuple(sorted(documented.sage())) 

 

 

FUNCTIONS = load_or_compute('functions', list_functions)