1Function: alias
2Section: programming/specific
3C-Name: alias0
4Prototype: vrr
5Help: alias(newsym,sym): defines the symbol newsym as an alias for the symbol
6 sym.
7Doc: defines the symbol \var{newsym} as an alias for the symbol \var{sym}:
8 \bprog
9 ? alias("det", "matdet");
10 ? det([1,2;3,4])
11 %1 = -2
12 @eprog\noindent
13 You are not restricted to ordinary functions, as in the above example:
14 to alias (from/to) member functions, prefix them with `\kbd{\_.}';
15 to alias operators, use their internal name, obtained by writing
16 \kbd{\_} in lieu of the operators argument: for instance, \kbd{\_!} and
17 \kbd{!\_} are the internal names of the factorial and the
18 logical negation, respectively.
19 \bprog
20 ? alias("mod", "_.mod");
21 ? alias("add", "_+_");
22 ? alias("_.sin", "sin");
23 ? mod(Mod(x,x^4+1))
24 %2 = x^4 + 1
25 ? add(4,6)
26 %3 = 10
27 ? Pi.sin
28 %4 = 0.E-37
29 @eprog
30 Alias expansion is performed directly by the internal GP compiler.
31 Note that since alias is performed at compilation-time, it does not
32 require any run-time processing, however it only affects GP code
33 compiled \emph{after} the alias command is evaluated. A slower but more
34 flexible alternative is to use variables. Compare
35 \bprog
36 ? fun = sin;
37 ? g(a,b) = intnum(t=a,b,fun(t));
38 ? g(0, Pi)
39 %3 = 2.0000000000000000000000000000000000000
40 ? fun = cos;
41 ? g(0, Pi)
42 %5 = 1.8830410776607851098 E-39
43 @eprog\noindent
44 with
45 \bprog
46 ? alias(fun, sin);
47 ? g(a,b) = intnum(t=a,b,fun(t));
48 ? g(0,Pi)
49 %2 = 2.0000000000000000000000000000000000000
50 ? alias(fun, cos);  \\ Oops. Does not affect *previous* definition!
51 ? g(0,Pi)
52 %3 = 2.0000000000000000000000000000000000000
53 ? g(a,b) = intnum(t=a,b,fun(t)); \\ Redefine, taking new alias into account
54 ? g(0,Pi)
55 %5 = 1.8830410776607851098 E-39
56 @eprog
57
58 A sample alias file \kbd{misc/gpalias} is provided with
59 the standard distribution.
60