[GAP Forum] Identical objects that are indices (not lists) ?

mike newman m.newman at qmul.ac.uk
Tue Apr 5 16:49:57 BST 2005


Hi,

I am a new GAP user, and am wondering if it is possible to have the nifty
feature of identical lists extend to simple objects (ie: variables that
have no subobjects), or failing that, something like what in C might be
called a pointer.

Specifically, I wish to operate on the elements of a matrix in two 
slightly different cases:
1) operate only on those indices (i,j) where i<=j
2) operate on all indices (i,j)

So, my simplified GAP fantasy-code looks like:

abc := function(A,flag)
	local i,j,jj;

	if flag then
		jj := PleaseMakeIdenticalCopy(i);	# ?!?
	else
		jj := 1;
	fi

	for i in [1..d] do for j in [jj..d] do
		# various_functions(i, j, A[i][j])
		# same for both cases
	od; od;
end;

Thus if flag=true, then jj and i would in fact be the same object 
(initially unset, of course); otherwise, jj is just a variable whose value 
is 1.


Making jj be a pointer would work too, but I find no mention of pointers
or anything similar in the GAP manual. Simply typing in two different
versions of function will of course work, but seems dangerous from the
point of view of maintenance (the body may change over time but always be
independent of which case). I can think of other ways of accomplishing
this with various degrees of (in)elegance, but the "identical object"
scenario seems so perfect...

Is there some nice GAP way to accomplish this? For what it's worth, this
is a somewhat time-critical section of code, so I would prefer not to
introduce too large a decision structure if possible.

comments appreciated,
Mike Newman




More information about the Forum mailing list