[GAP Forum] can one define identifiers like f1, f2, f3 in an automatic way?

Alexander Hulpke ahulpke at gmail.com
Sun Mar 20 21:33:51 GMT 2011


Dear Forum,

On Mar 21, 2011, at 5:17 AM, Igor Korepanov wrote:

> Dear Forum,
> 
> When I worked in Maple, it was possible to define an identifier like   f2  in such a way: first write
> n:=2;
> and then write   f||n .
> 
> That is, concatenate symbols to make an identifier for a variable or a function.
> 
> Is something like that possible in GAP ?

Assuming you want these variables to be global variables, the easiest way probably is

ASS_GVAR(string,value)

For example, you could use

ASS_GVAR("PiAppox",355/113);
or -- your example --
ASS_GVAR(Concatenation("f",String(3-1)),   12345 );

ASS_GVAR will overwrite variables without warning. there also is
ISBOUND_GVAR(string) and UNBIND_GLOBAL(string) to test or remove boundedness.

For generators of a free group or finitely presented group, there also is `AssignGeneratorVariables'.

(Luca Giuzzi's code of course also will work and is essentially the only way how one can do `eval(..)' for arbitrary string expressions.

Best,

    Alexander Hulpke

-- Colorado State University, Department of Mathematics,
Weber Building, 1874 Campus Delivery, Fort Collins, CO 80523-1874, USA
email: hulpke at math.colostate.edu, Phone: ++1-970-4914288
http://www.math.colostate.edu/~hulpke






More information about the Forum mailing list