Next: Primitive Procedures, Previous: Procedure Operations, Up: Procedures [Contents][Index]

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

`min`and`max`.`Min`must be an exact non-negative integer.`Max`must be an exact non-negative integer at least as large as`min`. Alternatively,`max`may 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:
**procedure-arity?***object*¶ Returns ‘

`#t`’ if`object`is an arity object, and ‘`#f`’ otherwise.

- procedure:
**procedure-arity-min***arity*¶ - procedure:
**procedure-arity-max***arity*¶ 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

`procedure`accepts. 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`’ if`procedure`accepts`arity`, and ‘`#f`’ otherwise.

- procedure:
**procedure-of-arity?***object arity*¶ Returns ‘

`#t`’ if`object`is a procedure that accepts`arity`, and ‘`#f`’ otherwise. Equivalent to:(and (procedure?

`object`) (procedure-arity-valid?`object``arity`))

- procedure:
**guarantee-procedure-of-arity***object arity caller*¶ Signals an error if

`object`is not a procedure accepting`arity`.`Caller`is 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:
**thunk?***object*¶ Returns ‘

`#t`’ if`object`is a procedure that accepts zero arguments, and ‘`#f`’ otherwise. Equivalent to:(procedure-of-arity?

`object`0)

Next: Primitive Procedures, Previous: Procedure Operations, Up: Procedures [Contents][Index]