> < ^ From:

< ^ Subject:

Dear GAP Forum,

There is no problem (although some Computer Scientists would say that it is a

bad idea) with a GAP function modifying its arguments. As a an example here

is a function which swaps the first elements of its two list arguments and

returns true if they are equal, false if not, and fail if one of the lists had

no first entry.

foo := function(l1,l2) local x; if not IsBound(l1[1]) or not IsBound(l2[1]) then return fail; fi; if l1[1] = l2[1] then return true; fi; x := l1[1]; l1[1] := l2[1]; l2[1] := x; return false; end; I can then do: gap> l := [1,2,3,4]; m:= [4,3,2,1]; [ 1, 2, 3, 4 ] [ 4, 3, 2, 1 ] gap> foo(l,m); false gap> l; [ 4, 2, 3, 4 ] gap> m; [ 1, 3, 2, 1 ] gap>

I hope this helps,

Steve Linton

-- Steve Linton School of Computer Science & Centre for Interdisciplinary Research in Computational Algebra University of St Andrews Tel +44 (1334) 463269 http://www-theory.dcs.st-and.ac.uk/~sal Fax +44 (1334) 463278

> < [top]