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.
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’.
Returns ‘#t’ if object is an arity object, and ‘#f’ otherwise.
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))
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)
Returns ‘#t’ if procedure accepts arity, and ‘#f’ otherwise.
Returns ‘#t’ if object is a procedure that accepts arity, and ‘#f’ otherwise. Equivalent to:
(and (procedure? object) (procedure-arity-valid? object arity))
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.
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]