From 1f63a568f57c45a41bf539fba591354a3cab302d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 5 Mar 2018 23:38:41 +0100 Subject: [PATCH] InstallImmediateMethod: make rank optional, tweak docs Clarify in the InstallImmediateMethod documentation that is an optional argument. Moreover, make the optional, too (if omitted, 0 is used as default value). --- lib/oper.g | 64 ++++++++++++++++++++++++++++++++++++++--------------- lib/oper1.g | 2 +- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/oper.g b/lib/oper.g index dc9ac492e7b..4fbe786e1f3 100644 --- a/lib/oper.g +++ b/lib/oper.g @@ -421,7 +421,7 @@ end ); ############################################################################# ## -#F InstallImmediateMethod( [, ], , , ) +#F InstallImmediateMethod( [, ], [, ], ) ## ## <#GAPDoc Label="InstallImmediateMethod"> ## @@ -431,7 +431,8 @@ end ); ## ## installs method as an ## immediate method for opr, which must be an attribute or a -## property, with requirement filter and rank rank. +## property, with requirement filter and rank rank +## (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 ## method among the immediate methods for opr. ## If supplied, info should be a short but informative string @@ -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(,,,)"); + 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( [, ], , , )"); + fi; + end ); diff --git a/lib/oper1.g b/lib/oper1.g index 1e48d6cba24..abb644722d7 100644 --- a/lib/oper1.g +++ b/lib/oper1.g @@ -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