This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Access procedure parameters

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


args(i .. j)


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.


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)):
  if args(0) >= 3 then
    print(Unquoted, "second, third argument" = args(2..3)):
number of arguments = 0
sequence of all arguments =
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;
  args(1), context(args(1))
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)))
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:


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?