From 121000e43a30d187f3567a9827d957a6d26d5125 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 2 Apr 2025 14:33:43 +0100 Subject: [PATCH 1/4] Add InstallDeprecatedMethod --- gap/obselete.gi | 2 + gap/obsolete.gd | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 gap/obselete.gi create mode 100644 gap/obsolete.gd diff --git a/gap/obselete.gi b/gap/obselete.gi new file mode 100644 index 000000000..3023c0c61 --- /dev/null +++ b/gap/obselete.gi @@ -0,0 +1,2 @@ +Read("obsolete.gd"); +DeclareDeprecatedSynonym("DigraphDijkstra", DigraphShortestPaths); diff --git a/gap/obsolete.gd b/gap/obsolete.gd new file mode 100644 index 000000000..6987f4ecc --- /dev/null +++ b/gap/obsolete.gd @@ -0,0 +1,106 @@ +GetFunctionName := function(func) + local names, name; + names := Names(GLOBAL); + for name in names do + if IsBound(name) and Eval(name) = func then + return name; + fi; + od; + return func+ "cannot be found"; +end; + +DeclareDeprecatedSynonym := function(oldName, newFunc) + local newName, warningMsg; + + newName := GetFunctionName(newFunc); + warningMsg := Concatenation(oldName, " is deprecated. Instead use ", newName, "."); + + DeclareOperation(oldName, [ ]); + InstallMethod(oldName, [ ], function() + Warning(warningMsg); + return newFunc(); + end); + + DeclareOperation(oldName, [ IsObject ]); + InstallMethod(oldName, [ IsObject ], function(a) + Warning(warningMsg); + return newFunc(a); + end); + + DeclareOperation(oldName, [ IsObject, IsObject ]); + InstallMethod(oldName, [ IsObject, IsObject ], function(a, b) + Warning(warningMsg); + return newFunc(a, b); + end); + + DeclareOperation(oldName, [ IsObject, IsObject, IsObject ]); + InstallMethod(oldName, [ IsObject, IsObject, IsObject ], function(a, b, c) + Warning(warningMsg); + return newFunc(a, b, c); + end); + + DeclareOperation(oldName, [ IsObject, IsObject, IsObject, IsObject ]); + InstallMethod(oldName, [ IsObject, IsObject, IsObject, IsObject ], function(a, b, c, d) + Warning(warningMsg); + return newFunc(a, b, c, d); + end); +end; + + + + +InstallDeprecatedMethod := function(oldName, newName, info, filters, func) + local warningMsg, newMethod, args; + warningMsg := Concatenation(oldName, " is deprecated. Instead use ", newName, "."); + + args := Length(filters); + if args = 0 then + newMethod := function(args...) + Warning(warningMsg); + return func(); + end; + elif args = 1 then + newMethod := function(a) + Warning(warningMsg); + return func(a); + end; + elif args = 2 then + newMethod := function(a, b) + Warning(warningMsg); + return func(a, b); + end; + elif args = 3 then + newMethod := function(a, b, c) + Warning(warningMsg); + return func(a, b, c); + end; + elif args = 4 then + newMethod := function(a, b, c, d) + Warning(warningMsg); + return func(a, b, c, d); + end; + elif args = 5 then + newMethod := function(a, b, c, d, e) + Warning(warningMsg); + return func(a, b, c, d, e); + end; + elif args = 6 then + newMethod := function(a, b, c, d, e, f) + Warning(warningMsg); + return func(a, b, c, d, e, f); + end; + else + Error("Unsupported args: ", args); + fi; + + InstallMethod(oldName, info, filters, newMethod); +end; + +DeclareDeprecatedSynonym := function(oldName, newName) + local i, method; + for i in [0 .. 6] do + for method in MethodsOperation(newName, i) do + InstallDeprecatedMethod(oldName, NameFunction(newName), method.info, method.argFilt, method.func); + od; + od; +end; From dd645c5c6f4d21a7c9749ef4926171ada2e0ab9a Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 2 Apr 2025 14:50:00 +0100 Subject: [PATCH 2/4] Removed an older version of code from .gd and fixed the file name for .gi (typo) --- gap/obsolete.gd | 51 -------------------------------- gap/{obselete.gi => obsolete.gi} | 0 2 files changed, 51 deletions(-) rename gap/{obselete.gi => obsolete.gi} (100%) diff --git a/gap/obsolete.gd b/gap/obsolete.gd index 6987f4ecc..b88b906cf 100644 --- a/gap/obsolete.gd +++ b/gap/obsolete.gd @@ -1,54 +1,3 @@ -GetFunctionName := function(func) - local names, name; - names := Names(GLOBAL); - for name in names do - if IsBound(name) and Eval(name) = func then - return name; - fi; - od; - return func+ "cannot be found"; -end; - -DeclareDeprecatedSynonym := function(oldName, newFunc) - local newName, warningMsg; - - newName := GetFunctionName(newFunc); - warningMsg := Concatenation(oldName, " is deprecated. Instead use ", newName, "."); - - DeclareOperation(oldName, [ ]); - InstallMethod(oldName, [ ], function() - Warning(warningMsg); - return newFunc(); - end); - - DeclareOperation(oldName, [ IsObject ]); - InstallMethod(oldName, [ IsObject ], function(a) - Warning(warningMsg); - return newFunc(a); - end); - - DeclareOperation(oldName, [ IsObject, IsObject ]); - InstallMethod(oldName, [ IsObject, IsObject ], function(a, b) - Warning(warningMsg); - return newFunc(a, b); - end); - - DeclareOperation(oldName, [ IsObject, IsObject, IsObject ]); - InstallMethod(oldName, [ IsObject, IsObject, IsObject ], function(a, b, c) - Warning(warningMsg); - return newFunc(a, b, c); - end); - - DeclareOperation(oldName, [ IsObject, IsObject, IsObject, IsObject ]); - InstallMethod(oldName, [ IsObject, IsObject, IsObject, IsObject ], function(a, b, c, d) - Warning(warningMsg); - return newFunc(a, b, c, d); - end); -end; - - - - InstallDeprecatedMethod := function(oldName, newName, info, filters, func) local warningMsg, newMethod, args; warningMsg := Concatenation(oldName, " is deprecated. Instead use ", newName, "."); diff --git a/gap/obselete.gi b/gap/obsolete.gi similarity index 100% rename from gap/obselete.gi rename to gap/obsolete.gi From da685ad7f287c27f0e21a028df823b0b400148e6 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 16 Apr 2025 14:32:47 +0100 Subject: [PATCH 3/4] Removed parameters from zero arg condition based on the PR comment --- gap/obsolete.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gap/obsolete.gd b/gap/obsolete.gd index b88b906cf..90069631c 100644 --- a/gap/obsolete.gd +++ b/gap/obsolete.gd @@ -4,7 +4,7 @@ InstallDeprecatedMethod := function(oldName, newName, info, filters, func) args := Length(filters); if args = 0 then - newMethod := function(args...) + newMethod := function() Warning(warningMsg); return func(); end; From 0ec97851354b92869461875d69874ea34d6ddcb0 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 16 Apr 2025 14:37:46 +0100 Subject: [PATCH 4/4] Fixed linting --- gap/obsolete.gd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gap/obsolete.gd b/gap/obsolete.gd index 90069631c..5c293754f 100644 --- a/gap/obsolete.gd +++ b/gap/obsolete.gd @@ -1,6 +1,7 @@ InstallDeprecatedMethod := function(oldName, newName, info, filters, func) local warningMsg, newMethod, args; - warningMsg := Concatenation(oldName, " is deprecated. Instead use ", newName, "."); + warningMsg := Concatenation(oldName, " is deprecated. Instead use ", + newName, "."); args := Length(filters); if args = 0 then @@ -49,7 +50,8 @@ DeclareDeprecatedSynonym := function(oldName, newName) local i, method; for i in [0 .. 6] do for method in MethodsOperation(newName, i) do - InstallDeprecatedMethod(oldName, NameFunction(newName), method.info, method.argFilt, method.func); + InstallDeprecatedMethod(oldName, NameFunction(newName), + method.info, method.argFilt, method.func); od; od; end;