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
|
##############################################################################
##
#W record.gi GAP4 package `Utils' Sebastian Gutsche
## Max Horn
## Stefan Kohl
#Y Copyright (C) 2015-2025, The GAP Group
#############################################################################
## this function has been transferred from RCWA
##
#F AssignGlobals( <record> )
##
## This auxiliary function assigns the record components of <record>
## to global variables with the same names.
##
BindGlobal( "AssignGlobals",
function ( record )
local names, name;
names := RecNames(record);
for name in names do
if IsBoundGlobal(name) then
if IsReadOnlyGlobal(name)
then
MakeReadWriteGlobal(name);
Info(InfoWarning,1,"The read-only global variable ",name,
" has been overwritten.");
else
Info(InfoUtils,1,"The global variable ",name,
" has been overwritten.");
fi;
UnbindGlobal(name);
fi;
BindGlobal(name,record.(name));
MakeReadWriteGlobal(name);
od;
Print("The following global variables have been assigned:\n",
Set(names),"\n");
end );
BindGlobal( "OptionRecordWithDefaults",
function(default, useroptions)
local name, ret;
ret := rec();
if IsList(useroptions) then
if IsEmpty(useroptions) then
return default;
elif Length(useroptions) = 1 then
useroptions := useroptions[1];
else
ErrorNoReturn("Too many arguments for function");
fi;
fi;
if not IsRecord(useroptions) then
ErrorNoReturn("Options should be a record");
fi;
ret := ShallowCopy(default);
for name in RecNames(useroptions) do
if not IsBound(default.(name)) then
ErrorNoReturn(Concatenation("Unknown option: " , name));
else
ret.(name) := useroptions.(name);
fi;
od;
return ret;
end);
#############################################################################
##
#E record.gi . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
|