Documentation

args

Access procedure parameters

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

args()
args(0)
args(i)
args(i .. j)

Description

args(0) returns the number of parameters of the current procedure.

args(i) returns the value of the ith parameter of the current procedure.

args 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(i..j) returns an expression sequence containing the ith up to the jth parameter.

In procedures with option 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.

Assigning values to formal parameters of a procedure changes the result of args. Cf. Example 4. args(0) remains unchanged.

Examples

Example 1

This 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 =
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 2

args 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)

Example 3

We 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)

Example 4

Assigning 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)

Parameters

i, j

Positive integers

Return Values

args(0) returns a nonnegative integer. All other calls return an arbitrary MuPAD® object or a sequence of such objects.

See Also

MuPAD Domains

MuPAD Functions

Was this topic helpful?