[GAP Forum] procedure to change a permutation, not returning it

Christopher Jefferson caj21 at st-andrews.ac.uk
Tue Apr 19 22:14:28 BST 2016


The short answer is no I'm afraid.

The slightly longer answer is while you can't do this, you can do something similar if you pass in a list containing a permutation, or a record with a permutation member, and change that. For example:

testperm := function(s)
  local i;
  i := 1;
  s[1] := s[1]^-1;
  Print(s,"\n");
  return i;
end;

gap> a:=[(1,2,3)];
[ (1,2,3) ]
gap> testperm(a);
[ (1,3,2) ]
1
gap> a;
[ (1,3,2) ]





You might think, why can I change lists? The rule is you can change members of a list (or members of a record), but not the list itself. For example, if in our function we wrote ' s := [(3,2,1)] ', we would find that didn't change a, because now we are changing s, not a member of s.

Chris



On 19/04/2016, 22:06, "forum-bounces at gap-system.org on behalf of Rafael Villarroel" <forum-bounces at gap-system.org on behalf of rafaelv at uaeh.edu.mx> wrote:

>
>Hello GAP forum,
>
>Is it possible to define a function that returns, say, an integer, but
>changes a permutation given as argument, as a side effect.
>
>Something like this:
>
>testperm := function(s)
>    local i;
>    i := 1;
>    s := s^-1;
>    Print(s,"\n");
>    return i;
>end;
>
>but that when running it like this...
>
>gap> a:=(1,2,3);
>(1,2,3)
>gap> testperm(a);
>(1,3,2)
>1
>gap> a;
>(1,2,3)
>
>...actually changes the permutation a.
>
>Thanks in advance,
>Rafael
>
>
>_______________________________________________
>Forum mailing list
>Forum at mail.gap-system.org
>http://mail.gap-system.org/mailman/listinfo/forum


More information about the Forum mailing list