[GAP Forum] is it possible to suppress displaying a return value from within a function?

Hulpke,Alexander Alexander.Hulpke at colostate.edu
Mon Oct 25 17:33:15 BST 2021


Dear Forum,

Will Chen asked:
> Normally when you write a function F that returns a value, entering "F();"
> into the command line will display the full return value of the function.
> You can suppress this output calling the function using the
> double-semicolon "F();;" in the terminal.
> 
> Is it possible to suppress this output from *within the function*? 

There isn’t a particular built-in feature for this, but since the outpus is produced by a call to `View`, you can achieve the same by installing a suitable method for `ViewObj`:

DONTSHOW:="DONT_SHOW_STRING";

InstallOtherMethod(ViewObj,"Ignore particular",[IsObject],2*SUM_FLAGS,
function(x)
  if IsIdenticalObj(DONTSHOW,x) then
    Print("<I won't show you this>”);  # delete the line to get no output
  else
    TryNextMethod();
  fi;
end);

Now an object that is assigned to the global `DONTSHOW` will give the output <I won't show you this>.  For example:

gap> DONTSHOW:=5;;
gap> [1,2,3,4,5,6,7];
[ 1, 2, 3, 4, <I won't show you this>, 6, 7 ]

If you delete the `Print` statement, nothing will be shown. By assigning the return value to the variable, this would let you do as you want.

Note that the test is `IsIdenticalObj`, not equality, to be guaranteed quick, but it means that it only recognizes the one, particular, specified object.

Best,

   Alexander Hulpke



More information about the Forum mailing list