Skip to content

Commit

Permalink
InstallImmediateMethod: make rank optional, tweak docs
Browse files Browse the repository at this point in the history
Clarify in the InstallImmediateMethod documentation that <info> is
an optional argument. Moreover, make the <rank> optional, too
(if omitted, 0 is used as default value).
  • Loading branch information
fingolfin committed Mar 5, 2018
1 parent f5c015f commit 1f63a56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
64 changes: 46 additions & 18 deletions lib/oper.g
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ end );

#############################################################################
##
#F InstallImmediateMethod( <opr>[, <info>], <filter>, <rank>, <method> )
#F InstallImmediateMethod( <opr>[, <info>], <filter>[, <rank>], <method> )
##
## <#GAPDoc Label="InstallImmediateMethod">
## <ManSection>
Expand All @@ -431,7 +431,8 @@ end );
## <Description>
## <Ref Func="InstallImmediateMethod"/> installs <A>method</A> as an
## immediate method for <A>opr</A>, which must be an attribute or a
## property, with requirement <A>filter</A> and rank <A>rank</A>.
## property, with requirement <A>filter</A> and rank <A>rank</A>
## (the rank can be omitted, in which case 0 is used as rank).
## The rank must be an integer value that measures the priority of
## <A>method</A> among the immediate methods for <A>opr</A>.
## If supplied, <A>info</A> should be a short but informative string
Expand Down Expand Up @@ -489,25 +490,52 @@ end );
## <#/GAPDoc>
##
BIND_GLOBAL( "InstallImmediateMethod", function( arg )
local pos, opr, info, filter, rank, method;

if LEN_LIST( arg ) = 4
and IS_OPERATION( arg[1] )
and IsFilter( arg[2] )
and IS_RAT( arg[3] )
and IS_FUNCTION( arg[4] ) then
INSTALL_IMMEDIATE_METHOD( arg[1], false, arg[2], arg[3], arg[4] );
INSTALL_METHOD( [ arg[1], [ arg[2] ], arg[4] ], false );
elif LEN_LIST( arg ) = 5
and IS_OPERATION( arg[1] )
and IS_STRING( arg[2] )
and IsFilter( arg[3] )
and IS_RAT( arg[4] )
and IS_FUNCTION( arg[5] ) then
INSTALL_IMMEDIATE_METHOD( arg[1], arg[2], arg[3], arg[4], arg[5] );
INSTALL_METHOD( [ arg[1], arg[2], [ arg[3] ], arg[5] ], false );
pos := 1;

if pos <= LEN_LIST( arg ) and IS_OPERATION( arg[pos] ) then
opr := arg[pos];
pos := pos + 1;
else
Error("usage: InstallImmediateMethod(<opr>,<filter>,<rank>,<method>)");
pos := -1;
fi;

if pos <= LEN_LIST( arg ) and IS_STRING( arg[pos] ) then
info := arg[pos];
pos := pos + 1;
else
info := false;
fi;

if pos <= LEN_LIST( arg ) and IsFilter( arg[pos] ) then
filter := arg[pos];
pos := pos + 1;
else
pos := -1;
fi;

if pos <= LEN_LIST( arg ) and IS_RAT( arg[pos] ) then
rank := arg[pos];
pos := pos + 1;
else
rank := 0;
fi;

if pos <= LEN_LIST( arg ) and IS_FUNCTION( arg[pos] ) then
method := arg[pos];
pos := pos + 1;
else
pos := -1;
fi;

if pos = LEN_LIST( arg ) + 1 then
INSTALL_IMMEDIATE_METHOD( opr, info, filter, rank, method );
INSTALL_METHOD( [ opr, info, [ filter ], method ], false );
else
Error("usage: InstallImmediateMethod( <opr>[, <info>], <filter>, <rank>, <method> )");
fi;

end );


Expand Down
2 changes: 1 addition & 1 deletion lib/oper1.g
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ BIND_GLOBAL( "INSTALL_METHOD",

# Check whether an info string is given,
# or whether the list of argument filters is given by a list of strings.
if IS_STRING_REP( arglist[2] ) then
if IS_STRING_REP( arglist[2] ) or arglist[2] = false then
info:= arglist[2];
pos:= 3;
else
Expand Down

0 comments on commit 1f63a56

Please sign in to comment.