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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#############################################################################
##
## This file is part of GAP, a system for computational discrete algebra.
## This file's authors include Thomas Breuer, Frank Celler.
##
## Copyright of GAP belongs to its developers, whose names are too numerous
## to list here. Please refer to the COPYRIGHT file for details.
##
## SPDX-License-Identifier: GPL-2.0-or-later
##
## This file contains methods for records.
## Compared to ⪆ 3, where records were used to represent domains and
## all kinds of external arithmetic objects, in ⪆ 4 there is no
## important role for records.
## So the standard library provides only methods for `PrintObj', `String',
## `=', and `<', and the latter two are not installed to compare records
## with objects in other families.
##
#############################################################################
##
#C IsRecord( <obj> )
#C IsRecordCollection( <obj> )
#C IsRecordCollColl( <obj> )
##
## <#GAPDoc Label="IsRecord">
## <ManSection>
## <Filt Name="IsRecord" Arg='obj' Type='Category'/>
## <Filt Name="IsRecordCollection" Arg='obj' Type='Category'/>
## <Filt Name="IsRecordCollColl" Arg='obj' Type='Category'/>
##
## <Description>
## <Index Subkey="for records">test</Index>
## <Example><![CDATA[
## gap> IsRecord( rec( a := 1, b := 2 ) );
## true
## gap> IsRecord( IsRecord );
## false
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareCategoryKernel( "IsRecord", IsObject, IS_REC );
DeclareCategoryCollections( "IsRecord" );
DeclareCategoryCollections( "IsRecordCollection" );
#############################################################################
##
#V RecordsFamily . . . . . . . . . . . . . . . . . . . . . family of records
##
## <ManSection>
## <Var Name="RecordsFamily"/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "RecordsFamily", NewFamily( "RecordsFamily", IS_REC ) );
#############################################################################
##
#V TYPE_PREC_MUTABLE . . . . . . . . . . . type of a mutable internal record
##
## <ManSection>
## <Var Name="TYPE_PREC_MUTABLE"/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "TYPE_PREC_MUTABLE",
NewType( RecordsFamily, IS_MUTABLE_OBJ and IS_REC and IsInternalRep ) );
#############################################################################
##
#V TYPE_PREC_IMMUTABLE . . . . . . . . type of an immutable internal record
##
## <ManSection>
## <Var Name="TYPE_PREC_IMMUTABLE"/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "TYPE_PREC_IMMUTABLE",
NewType( RecordsFamily, IS_REC and IsInternalRep ) );
#############################################################################
##
#o \.( <rec>, <name> ) . . . . . . . . . . . . . . . . get a component value
##
DeclareOperationKernel( ".", [ IsObject, IsObject ], ELM_REC );
#############################################################################
##
#o IsBound\.( <rec>, <name> ) . . . . . . . . . . . . . . test a component
##
DeclareOperationKernel( "IsBound.", [ IsObject, IsObject ], ISB_REC );
#############################################################################
##
#o \.\:\=( <rec>, <name>, <val> ) . . . . . . . . . . . . . assign a value
##
DeclareOperationKernel( ".:=", [ IsObject, IsObject, IsObject ], ASS_REC );
#############################################################################
##
#o Unbind\.( <rec>, <name> ) . . . . . . . . . . . . . . . unbind component
##
DeclareOperationKernel( "Unbind.", [ IsObject, IsObject ], UNB_REC );
#############################################################################
##
#A RecNames( <record> )
##
## <#GAPDoc Label="RecNames">
## <ManSection>
## <Attr Name="RecNames" Arg='record'/>
##
## <Description>
## returns a duplicate-free list of strings corresponding to the names of
## the record components of the record <A>record</A>.
## <P/>
## The list is sorted by <Ref Func="RNamObj" Label="for a string"/>
## for reasons of efficiency; see <Ref Oper="SortBy"/>.
## Therefore the ordering is consistent within one &GAP; session,
## but it is not necessarily consistent across different sessions.
## To obtain a result that is consistent across &GAP; sessions,
## apply <Ref Oper="Set"/> to the returned list.
## <P/>
## Note that given a string <C>name</C> containing the name of a record
## component, you can access the record component via
## <C><A>record</A>.(name)</C>,
## see Sections <Ref Sect="Accessing Record Elements"/>
## and <Ref Sect="Record Assignment"/>.
## <P/>
## <Example><![CDATA[
## gap> r := rec( a := 1, b := 2 );;
## gap> Set(RecNames( r )); # 'Set' because ordering depends on GAP session
## [ "a", "b" ]
## gap> Set(RecNames( r ), x -> r.(x));
## [ 1, 2 ]
## ]]></Example>
## <P/>
## Note that it is most efficient to assign components to a (new or old)
## record in the order given by <Ref Attr="RecNames" Style="Text"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "RecNames", IsRecord );
#############################################################################
##
#F NamesOfComponents( <comobj> )
##
## <#GAPDoc Label="NamesOfComponents">
## <ManSection>
## <Func Name="NamesOfComponents" Arg='comobj'/>
##
## <Description>
## For a component object <A>comobj</A>,
## <Ref Func="NamesOfComponents"/> returns a list of strings,
## which are the names of components currently bound in <A>comobj</A>.
## <P/>
## For a record <A>comobj</A> in internal representation,
## <Ref Func="NamesOfComponents"/> returns the result of
## <Ref Attr="RecNames"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "NamesOfComponents" );
#############################################################################
##
#V IdentifierLetters . . . . . . . .characters allowed in normal identifiers
##
## This is used to produce warning messages when the XxxxGlobal functions
## are applied to a name which could not be read in by the parser without
## escapes
##
BIND_GLOBAL( "IdentifierLetters",
Immutable("0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz") );
IsSet( IdentifierLetters ); # ensure GAP knows that this is a set
#############################################################################
##
#F SetNamesForFunctionsInRecord( <rec-name>[, <record> ][, <field-names>])
##
## set the names of functions bound to components of a record.
##
DeclareGlobalFunction("SetNamesForFunctionsInRecord");
|