diff --git a/hpcgap/lib/filter.gi b/hpcgap/lib/filter.gi new file mode 100644 index 00000000000..7374183accf --- /dev/null +++ b/hpcgap/lib/filter.gi @@ -0,0 +1,72 @@ +## +## Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany +## (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland +## Copyright (C) 2002 The GAP Group +## +## This software is licensed under the GPL 2 or later, please refer +## to the COPYRIGHT.md and LICENSE files for details. +## + +############################################################################# +## +#V IdOfFilter +## +## <#GAPDoc Label="IdOfFilter"> +## +## +## +## +## +## finds the id of the filter filter, or the id of the filter +## with name name respectively. +## The id of a filter is equal to the +## position of this filter in the global FILTERS list. +##

+## Note that not every filter for which IsFilter(filter) +## returns true has an ID, only elementary filters do. +## +## +## <#/GAPDoc> +## +## Note that the filter ID is stored in FLAG1_FILTER for most filters, +## testers have the ID stored in FLAG2_FILTER, so the code below is +## more efficient than just iterating over the FILTERS list. +## +## +BIND_GLOBAL( "IdOfFilter", +function(filter) + local fid; + atomic readonly FILTER_REGION do + fid := FLAG1_FILTER(filter); + if fid > 0 and FILTERS[fid] = filter then + return fid; + fi; + fid := FLAG2_FILTER(filter); + if fid > 0 and FILTERS[fid] = filter then + return fid; + fi; + od; + return fail; +end); + +BIND_GLOBAL( "IdOfFilterByName", + name -> PositionProperty(FILTERS, f -> NAME_FUNC(f) = name) ); + +############################################################################# +## +#V FilterByName +## +## <#GAPDoc Label="FilterByName"> +## +## +## +## +## finds the filter with name name in the global FILTERS list. This +## is useful to find filters that were created but not bound to a global +## variable. +## +## +## <#/GAPDoc> +## +BIND_GLOBAL( "FilterByName", + name -> First(FILTERS, f -> NAME_FUNC(f) = name) ); diff --git a/hpcgap/lib/function.g b/hpcgap/lib/function.g index 93bbcc3af87..011bd9ede02 100644 --- a/hpcgap/lib/function.g +++ b/hpcgap/lib/function.g @@ -654,81 +654,6 @@ InstallMethod( ViewObj, "for a function", true, [IsFunction], 0, Print(" ) ... end"); end); -BIND_GLOBAL( "VIEW_STRING_OPERATION", function ( op ) - local class, flags, types, catok, repok, propok, seenprop, - t, res; - class := "Operation"; - if IS_IDENTICAL_OBJ(op,IS_OBJECT) then - class := "Filter"; - elif IS_CONSTRUCTOR(op) then - class := "Constructor"; - elif IsFilter(op) then - class := "Filter"; - flags := FLAGS_FILTER(op); - if flags <> false then - flags := TRUES_FLAGS(flags); - else - flags := []; - fi; - atomic readonly FILTER_REGION do - types := INFO_FILTERS{flags}; - od; - catok := true; - repok := true; - propok := true; - seenprop := false; - for t in types do - if not t in FNUM_REPS then - repok := false; - fi; - if not t in FNUM_CATS then - catok := false; - fi; - if not t in FNUM_PROS and not t in FNUM_TPRS then - propok := false; - fi; - if t in FNUM_PROS then - seenprop := true; - fi; - od; - if seenprop and propok then - class := "Property"; - elif catok then - class := "Category"; - elif repok then - class := "Representation"; - fi; - elif Tester(op) <> false then - # op is an attribute - class := "Attribute"; - fi; - - # Horrible. - res := "<"; - APPEND_LIST(res, class); - APPEND_LIST(res, " \""); - APPEND_LIST(res, NAME_FUNC(op)); - APPEND_LIST(res, "\">"); - return res; -end); - -BIND_GLOBAL( "PRINT_OPERATION", -function ( op ) - Print(VIEW_STRING_OPERATION(op)); -end); - -InstallMethod( ViewObj, - "for an operation", - [ IsOperation ], - PRINT_OPERATION ); - -InstallMethod( ViewString, - "for an operation", - [ IsOperation ], -function(op) - return VIEW_STRING_OPERATION(op); -end); - ############################################################################# ## #E diff --git a/hpcgap/lib/read1.g b/hpcgap/lib/read1.g index 2c01bf539a1..077eac11539 100644 --- a/hpcgap/lib/read1.g +++ b/hpcgap/lib/read1.g @@ -49,6 +49,7 @@ ReadLib( "permutat.g" ); ReadLib( "trans.g" ); ReadLib( "pperm.g" ); +ReadLib( "filter.gi" ); ReadLib( "object.gi" ); ReadLib( "listcoef.gd" ); ReadLib( "info.gd" ); diff --git a/hpcgap/tst/testinstall/type.tst b/hpcgap/tst/testinstall/type.tst new file mode 100644 index 00000000000..91206924689 --- /dev/null +++ b/hpcgap/tst/testinstall/type.tst @@ -0,0 +1,39 @@ +# +gap> test := x -> List([IsFilter, IsCategory, IsRepresentation, IsAttribute, IsProperty, IsOperation], f -> f(x));; +gap> test(IsFinite); +[ true, false, false, false, true, true ] + +# +gap> test(IsMagma); +[ true, true, false, false, false, true ] + +# +gap> test(IsCommutative); +[ true, false, false, false, true, true ] + +# +gap> test(Size); +[ false, false, false, true, false, true ] + +# +gap> test(Group); +[ false, false, false, false, false, false ] + +# +gap> test((1,2,3)); +[ false, false, false, false, false, false ] + +# +gap> test("hello, world"); +[ false, false, false, false, false, false ] + +# +gap> FilterByName("IsCommutative"); + +gap> CategoryByName("IsMagma"); + + +# +gap> f := function() atomic readonly FILTER_REGION do return ForAll([1..Length(FILTERS)], id -> id = IdOfFilter(FILTERS[id])); od; end;; +gap> f(); +true