5 Functions

Sections

  1. Information about a function
  2. Calling an function with a variable number of arguments
  3. Functions that do nothing
  4. Function Types

5.1 Information about a function

  • NameFunction( func ) F

    returns the name of a function. For operations, this is the name used in their declaration. For functions, this is the variable name they were first assigned to. (For some internal functions, this might be a name different from the name that is documented.) If no such name exists, "unknown" is returned.

    gap> NameFunction(SylowSubgroup);
    "SylowSubgroup"
    gap> Blubberflutsch:=x->x;;
    gap> NameFunction(Blubberflutsch);
    "Blubberflutsch"
    gap> a:=Blubberflutsch;;
    gap> NameFunction(a);             
    "Blubberflutsch"
    gap> NameFunction(x->x);
    "unknown"
    gap> NameFunction(NameFunction);
    "NAME_FUNC"
    

  • NumberArgumentsFunction( func ) F

    returns the number of arguments the function func accepts. For functions that use arg to take a variable number of arguments, as well as for operations, -1 is returned. For attributes, 1 is returned.

    gap> NumberArgumentsFunction(function(a,b,c,d,e,f,g,h,i,j,k)return 1;end); 
    11
    gap> NumberArgumentsFunction(Size);                   
    1
    gap> NumberArgumentsFunction(IsCollsCollsElms);
    3
    gap> NumberArgumentsFunction(Sum);               
    -1
    

    5.2 Calling an function with a variable number of arguments

  • CallFuncList( func, args ) F

    returns the result, when calling function func with the arguments given in the list args. This can be used to call a function with a variable number of arguments.

    gap> CallFuncList(\+,[6,7]); 
    13
    

    5.3 Functions that do nothing

    The following functions return fix results (or just their own argument). They can be useful in places when the syntax requires a function, but actually no functionality is required. So ReturnTrue is often used as family predicate in InstallMethod (see InstallMethod in ``Programming in GAP'').

  • ReturnTrue( ... ) F

    This function takes any number of arguments, and always returns true.

  • ReturnFalse( ... ) F

    This function takes any number of arguments, and always returns false.

  • ReturnFail( ... ) F

    This function takes any number of arguments, and always returns fail.

  • IdFunc( obj ) F

    returns obj.

    5.4 Function Types

    Functions are GAP objects and thus have categories and a family.

  • IsFunction( obj ) C

    is the category of functions.

  • IsOperation( obj ) C

    is the category of operations. Every operation is a function, but not vice versa.

  • FunctionsFamily V

    is the family of all functions.

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000