Next: Primitive Procedures, Previous: Procedure Operations, Up: Procedures

Each procedure has an arity, which is the minimum and (optionally) maximum number of arguments that it will accept. MIT/GNU Scheme provides an abstraction that represents arity, and tests for the apparent arity of a procedure.

Arity objects come in two forms: the simple form, an exact
non-negative integer, represents a fixed number of arguments. The
general form is a pair whose `car`

represents the minimum number
of arguments and whose `cdr`

is the maximum number of arguments.

— procedure: **make-procedure-arity**` min `[`max `[`simple-ok?`]]

Returns an arity object made from

minandmax.Minmust be an exact non-negative integer.Maxmust be an exact non-negative integer at least as large asmin. Alternatively,maxmay be omitted or given as `#f', which represents an arity with no upper bound.If

simple-ok?is true, the returned arity is in the simple form (an exact non-negative integer) when possible, and otherwise is always in the general form.Simple-ok?defaults to `#f'.

— procedure: **guarantee-procedure-arity**` object caller`

Signals an error if

objectis not an arity object.Calleris a symbol that is printed as part of the error message and is intended to be the name of the procedure where the error occurs.

— procedure: **procedure-arity-min**` arity`

— procedure:**procedure-arity-max**` arity`

— procedure:

Return the lower and upper bounds of

arity, respectively.

The following procedures test for the apparent arity of a procedure.
The results of the test may be less restrictive than the effect of
calling the procedure. In other words, these procedures may indicate
that the procedure will accept a given number of arguments, but if you
call the procedure it may signal a
`condition-type:wrong-number-of-arguments`

error. For example,
here is a procedure that appears to accept any number of arguments,
but when called will signal an error if the number of arguments is not
one:

(lambda arguments (apply car arguments))

— procedure: **procedure-arity**` procedure`

Returns the arity that

procedureaccepts. The result may be in either simple or general form.(procedure-arity (lambda () 3)) => (0 . 0) (procedure-arity (lambda (x) x)) => (1 . 1) (procedure-arity car) => (1 . 1) (procedure-arity (lambda x x)) => (0 . #f) (procedure-arity (lambda (x . y) x)) => (1 . #f) (procedure-arity (lambda (x #!optional y) x)) => (1 . 2)

— procedure: **procedure-arity-valid?**` procedure arity`

Returns `

#t' ifprocedureacceptsarity, and `#f' otherwise.

— procedure: **procedure-of-arity?**` object arity`

Returns `

#t' ifobjectis a procedure that acceptsarity, and `#f' otherwise. Equivalent to:(and (procedure?object) (procedure-arity-valid?objectarity))

— procedure: **guarantee-procedure-of-arity**` object arity caller`

Signals an error if

objectis not a procedure acceptingarity.Calleris a symbol that is printed as part of the error message and is intended to be the name of the procedure where the error occurs.