Skip to content

Commit

Permalink
kernel: add RequireMutableSet helper in set.c
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 5, 2018
1 parent ccdc683 commit 8a9aa64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
40 changes: 10 additions & 30 deletions src/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "sysopt.h" // for SyInitializing


#define RequireMutableSet(funcname, op) \
RequireArgumentCondition(funcname, op, #op, IS_MUTABLE_OBJ(op) && IsSet(op), \
"must be a mutable proper set")


/****************************************************************************
**
*F IsSet( <list> ) . . . . . . . . . . . . . . . . . test if a list is a set
Expand Down Expand Up @@ -409,12 +414,7 @@ Obj FuncADD_SET (
UInt wasTab;

/* check the arguments */
while ( ! IS_MUTABLE_OBJ(set) || ! IsSet(set) ) {
set = ErrorReturnObj(
"AddSet: <set> must be a mutable proper set (not a %s)",
(Int)TNAM_OBJ(set), 0L,
"you can replace <set> via 'return <set>;'" );
}
RequireMutableSet("AddSet", set);
len = LEN_LIST(set);

/* perform the binary search to find the position */
Expand Down Expand Up @@ -533,12 +533,7 @@ Obj FuncREM_SET (
Obj *ptr;

/* check the arguments */
while ( ! IS_MUTABLE_OBJ(set) || ! IsSet(set) ) {
set = ErrorReturnObj(
"RemoveSet: <set> must be a mutable proper set (not a %s)",
(Int)TNAM_OBJ(set), 0L,
"you can replace <set> via 'return <set>;'" );
}
RequireMutableSet("RemoveSet", set);
len = LEN_LIST(set);

/* perform the binary search to find the position */
Expand Down Expand Up @@ -600,12 +595,7 @@ Obj FuncUNITE_SET (
Obj TmpUnion;

/* check the arguments */
while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) {
set1 = ErrorReturnObj(
"UniteSet: <set1> must be a mutable proper set (not a %s)",
(Int)TNAM_OBJ(set1), 0L,
"you can replace <set1> via 'return <set1>;'" );
}
RequireMutableSet("UniteSet", set1);
RequireSmallList("UniteSet", set2);
if ( ! IsSet(set2) ) set2 = SetList(set2);

Expand Down Expand Up @@ -773,12 +763,7 @@ Obj FuncINTER_SET (
UInt lenr; /* length of result set */

/* check the arguments */
while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) {
set1 = ErrorReturnObj(
"IntersectSet: <set1> must be a mutable proper set (not a %s)",
(Int)TNAM_OBJ(set1), 0L,
"you can replace <set1> via 'return <set1>;'" );
}
RequireMutableSet("IntersectSet", set1);
RequireSmallList("IntersectSet", set2);
if ( ! IsSet(set2) ) set2 = SetList(set2);

Expand Down Expand Up @@ -946,12 +931,7 @@ Obj FuncSUBTR_SET (
UInt ll;

/* check the arguments */
while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) {
set1 = ErrorReturnObj(
"SubtractSet: <set1> must be a mutable proper set (not a %s)",
(Int)TNAM_OBJ(set1), 0L,
"you can replace <set1> via 'return <set1>;'" );
}
RequireMutableSet("SubtractSet", set1);
RequireSmallList("SubtractSet", set2);
if ( ! IsSet(set2) ) set2 = SetList(set2);

Expand Down
10 changes: 5 additions & 5 deletions tst/testinstall/kernel/set.tst
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ false
gap> ADD_SET;
function( set, val ) ... end
gap> ADD_SET(1,1);
Error, AddSet: <set> must be a mutable proper set (not a integer)
Error, AddSet: <set> must be a mutable proper set (not the integer 1)

#
gap> REM_SET;
function( set, val ) ... end
gap> REM_SET(1,1);
Error, RemoveSet: <set> must be a mutable proper set (not a integer)
Error, RemoveSet: <set> must be a mutable proper set (not the integer 1)

#
gap> UNITE_SET;
function( set1, set2 ) ... end
gap> UNITE_SET(1,1);
Error, UniteSet: <set1> must be a mutable proper set (not a integer)
Error, UniteSet: <set1> must be a mutable proper set (not the integer 1)
gap> UNITE_SET([],1);
Error, UniteSet: <set2> must be a small list (not the integer 1)
gap> UNITE_SET([],[]);
Expand All @@ -66,7 +66,7 @@ gap> UNITE_SET([],[]);
gap> INTER_SET;
function( set1, set2 ) ... end
gap> INTER_SET(1,1);
Error, IntersectSet: <set1> must be a mutable proper set (not a integer)
Error, IntersectSet: <set1> must be a mutable proper set (not the integer 1)
gap> INTER_SET([],1);
Error, IntersectSet: <set2> must be a small list (not the integer 1)
gap> INTER_SET([],[]);
Expand All @@ -75,7 +75,7 @@ gap> INTER_SET([],[]);
gap> SUBTR_SET;
function( set1, set2 ) ... end
gap> SUBTR_SET(1,1);
Error, SubtractSet: <set1> must be a mutable proper set (not a integer)
Error, SubtractSet: <set1> must be a mutable proper set (not the integer 1)
gap> SUBTR_SET([],1);
Error, SubtractSet: <set2> must be a small list (not the integer 1)
gap> SUBTR_SET([],[]);
Expand Down

0 comments on commit 8a9aa64

Please sign in to comment.