Deletes an alias-definition
This functionality does not run in MATLAB.
unalias(x1, x2, …, <Global>) unalias(<Global>)
unalias(x) deletes the abbreviation or macro x. To delete a macro defined by alias(f(y1, y2, ...) = object), use unalias(f). If no alias for x or f, respectively, is defined currently, the call is ignored.
unalias() deletes all abbreviations and macros.
Multiple alias definitions may be deleted by a single call of unalias. The call unalias() deletes all currently defined aliases.
unalias does not evaluate its arguments.
If an identifier is used as an abbreviation, it is not possible to enter this identifier in its literal meaning any longer.
Note: In particular, it is necessary to use unalias before another abbreviation or macro for the same identifier can be defined. Cf. Example 4.
Assigning a value to one of the identifiers on the left hand side of an alias definition, or deleting its value has no effect on the alias substitution, neither in the input nor in the output. See Example 7.
alias with at least one argument and unalias change the parser configuration in the way described in the "Details" section.
We define d as a shortcut for diff:
delete f, g, x, y: alias(d = diff): d(sin(x), x) = diff(sin(x), x); d(f(x, y), x) = diff(f(x, y), x)
We define a macro Dx(f) for diff(f(x), x). Note that hold does not prevent alias substitution:
alias(Dx(f) = diff(f(x), x)): Dx(sin); Dx(f + g); hold(Dx(f + g))
After the call unalias(d, Dx), no alias substitutions happen any longer:
unalias(d, Dx): d(sin(x), x), diff(sin(x), x), d(f(x, y), x), diff(f(x, y), x); Dx(sin), Dx(f + g)
Suppose we want to avoid typing longhardtotypeident and therefore define an abbreviation a for it:
longhardtotypeident := 10; alias(a = longhardtotypeident):
Since alias does not evaluate its arguments, a is now an abbreviation for longhardtotypeident and not for the number 10:
a + 1, hold(a) + 1, eval(hold(a) + 1)
longhardtotypeident := 2: a + 1, hold(a) + 1, eval(hold(a) + 1)
However, by default alias back-substitution in the output happens for both the identifier and its current value:
2, 10, longhardtotypeident, hold(longhardtotypeident)
The command Pref::alias(FALSE) switches alias resubstitution off:
p := Pref::alias(FALSE): a, hold(a), 2, longhardtotypeident, hold(longhardtotypeident); Pref::alias(p): unalias(a):
Aliases are substituted and not just replaced textually. In the following example, 3*succ(u) is replaced by 3*(u+1), and not by 3*u+1, which a search-and-replace function in a text editor would produce:
alias(succ(x) = x + 1): 3*succ(u); unalias(succ):
We define a to be an abbreviation for b. Then the next alias definition is really an alias definition for b:
delete a, b: alias(a = b): alias(a = 2): type(a), type(b); unalias(b):
Use unalias first before defining another alias for the identifier a:
unalias(a): alias(a = 2): type(a), type(b); unalias(a):
A macro definition, however, can be added if the newly defined macro has a different number of arguments. unalias(a) removes all macros defined for a:
alias(a(x)=sin(x^2)): a(y); alias(a(x)=cos(x^2)):
Error: The operand is invalid. [_power] Evaluating: alias
alias(a(x, y) = sin(x + y)): a(u, v); alias(): unalias(a):
a(x) = sin(x^2)
a(x, y) = sin(x + y)
A macro definition has no effect when called with the wrong number of arguments, and the sequence of arguments is not flattened:
alias(plus(x, y) = x + y): plus(1), plus(3, 2), plus((3, 2)); unalias(plus):
Expression sequences may appear on the right hand side of an alias definition, but they have to be enclosed in parenthesis:
alias(x = (1, 2)): f := 0, 1, 2, x; nops(f); unalias(x):
An identifier used as an abbreviation may still exist in its literal meaning inside expressions that were entered before the alias definition:
delete x: f := [x, 1]: alias(x = 1): f; map(f, type); unalias(x):
It does not matter whether the identifier used as an alias has a value:
a := 5: alias(a = 7): 7, 5; print(a); unalias(a):
Alias definitions also apply to input from files or strings:
alias(a = 3): type(text2expr("a")); unalias(a)
An alias is valid for all input that is parsed after executing alias. A statement in a command line is not parsed before the previous commands in that command line have been executed. In the following example, the alias is already in effect for the second statement:
alias(a = 3): type(a); unalias(a)
This can be changed by entering additional parentheses:
(alias(a = 3): type(a)); unalias(a)
We define b to be an alias for c, which in turn is defined to be an alias for 2. It is recommended to avoid such chains of alias definitions beacuse of some probably unwanted effects.
Now each b in the input is replaced by c, but no additional substitution step is taken to replace this again by 2:
On the other hand, the number 2 is replaced by c in every output and that c is then replaced by b:
When called without arguments, alias just displays all aliasses that are currently in effect:
alias(a = 5, F(x) = sin(x^2)): alias(); unalias(F, a):
F(x) = sin(x^2)
a = 5
x1, x2, …
identifiers or symbolic expressions of the form f(y1, y2, …), with identifiers f, y1, y2, ...
object1, object2, …
Any MuPAD® objects
Definition of an alias in the global parser context.
When an alias is defined in a library or package source file, it will be deleted automatically after reading the file. With option Global the alias is not active in the file being read, but in the interactive level after reading of the file is finished.
Both alias and unalias return the void object of type DOM_NULL.
The aliases are stored in the parser configuration table displayed by _parser_config(). Note that by default, alias back-substitution happens for the right hand sides of the equations in this table, but not for the indices. Use print(_parser_config()) to display this table without alias back-substitution.
Aliases are not in effect while a file is read using read or fread with option Plain. This is true in particular for all library files read with loadproc. Conversely, if an alias is defined in a file which is read with option Plain, the alias is only in effect until the file has been read completely.