args -- access procedure
parameters
Introductionargs(0) returns the number of parameters
of the current procedure.
args(i) returns the value of the
ith parameter of the current procedure.
Call(s)args()
args(0)
args(i)
args(i..j)
Parametersi, j |
- | positive integers |
Returnsargs(0) returns a nonnegative integer. All other calls return an arbitrary
MuPAD object or a sequence of such objects.
Related
Functionscontext, DOM_PROC, DOM_VAR, Pref::typeCheck, proc, procname, testargs
Detailsargs accesses the actual parameters of a procedure and can only be used in procedures. It is
mainly intended for procedures with a variable number of arguments,
since otherwise parameters can simply be accessed by their names.args() returns an expression sequence of all actual parameters.args(0) returns the number of actual
parameters.args(i) returns the value of the
ith parameter.args(i..j) returns an expression sequence containing the ith
up to the jth parameter.hold,
args returns the parameters without further evaluation. Use context or eval to enforce a subsequent
evaluation. See example 2.procname(args())
returns a symbolic function call of the current procedure with
evaluated arguments.args. Cf. example 4.
args(0) remains unchanged.args is a function of the system kernel.
Example
1This example demonstrates the various ways of using
args:
>> f := proc() begin
print(Unquoted, "number of arguments" = args(0)):
print(Unquoted, "sequence of all arguments" = args()):
if args(0) > 0 then
print(Unquoted, "first argument" = args(1)):
end_if:
if args(0) >= 3 then
print(Unquoted, "second, third argument" = args(2..3)):
end_if:
end_proc:
>> f():
number of arguments = 0
sequence of all arguments = null()
>> f(42):
number of arguments = 1
sequence of all arguments = 42
first argument = 42
>> f(a, b, c, d):
number of arguments = 4
sequence of all arguments = (a, b, c, d)
first argument = a
second, third argument = (b, c)
Example
2args does not evaluate the returned
parameters in procedures with the option hold. Use context to achieve this:
>> f := proc()
option hold;
begin
args(1), context(args(1))
end_proc:
>> delete x, y: x := y: y := 2: f(x)
x, 2
Example
3We use args to access parameters of a
procedure with an arbitrary number of arguments:
>> f := proc() begin
args(1) * _plus(args(2..args(0)))
end_proc:
f(2, 3), f(2, 3, 4)
6, 14
Example
4Assigning values to formal parameters affects the
behavior of args. In the following example,
args returns the value 4, which is assigned
inside the procedure, and not the value 1, which is the
argument of the procedure call:
>> f := proc(a) begin a := 4; args() end_proc: f(1)
4
args.