• egg

## srfi-102

Procedure Arity Inspection

## Documentation

From the Withdrawn SRFI 102.

This implementation uses the Chicken procedure-information facility.

### SRFI 102 (Withdrawn: 2013/02/24)

#### procedure-arity

[procedure] (procedure-arity PROCEDURE) => ARITY-OBJECT

Produces an arity-object representing the arity of PROCEDURE. If #f results, no information is available for PROCEDURE.

If this procedure produces an exact-non-negative-integer, K, then PROCEDURE accepts exactly K arguments; applying PROCEDURE to some number of arguments other than K will result in an arity error.

If this procedure produces an arity-at-least-object, A, then PROCEDURE accepts (arity-at-least-value A) or more arguments; applying PROCEDURE to some number of arguments less than (arity-at-least-value A) will result in an arity error.

If this procedure produces a list, then PROCEDURE accepts any of the arities described by the elements of the list; applying PROCEDURE to some number of arguments not described by an element of the list will result in an arity error.

#### procedure-arity-includes?

[procedure] (procedure-arity-includes? PROCEDURE K) => BOOLEAN

Returns #t if the PROCEDURE can accept K arguments and #f otherwise. If this procedure returns #f, applying PROCEDURE to K arguments will result in an arity error.

#### arity-at-least?

[procedure] (arity-at-least? OBJECT) => BOOLEAN

Returns #t if OBJECT is an arity-at-least-object and #f otherwise.

#### arity-at-least-value

[procedure] (arity-at-least-value A) => INTEGER

Returns the exact-non-negative-integer denoting the minimum number of arguments required by the given A.

### Extensions

#### fixed-arity->arity-at-least

[procedure] (fixed-arity->arity-at-least K) => ARITY-AT-LEAST-OBJECT

Returns a scalar arity-at-least-object for the supplied exact-non-negative-integer K.

#### procedure-arity-available?

[procedure] (procedure-arity-available? PROCEDURE) => BOOLEAN

Returns #t if the PROCEDURE has arity information.

#### procedure-fixed-arity?

[procedure] (procedure-fixed-arity? PROCEDURE) => BOOLEAN

Returns #t if the PROCEDURE accepts only a fixed number of arguments.

#### procedure-minimum-arity

[procedure] (procedure-minimum-arity PROCEDURE) => INTEGER

Returns the minimum number of arguments acceptable by the PROCEDURE.

#### procedure-arity-set!

[procedure] (procedure-arity-set! PROCEDURE [A | K] ...)

PROCEDURE has arity information from one or more A or K.

K
exact-non-negative-integer
A
scalar arity-at-least-object

#### append-procedure-arity!

[procedure] (append-procedure-arity! PROCEDURE A | K)

PROCEDURE has arity information from an A or K.

K
exact-non-negative-integer
A
scalar arity-at-least-object

## Usage

`(require-extension srfi-102)`

## Examples

• See the "run.scm" test source.

## Notes

• To call this a work in progress is an understatement. The pulling of procedure arity & name from the lambda-info type is a hack.
• The module procedure-introspection provides the routines for this extension.
• The withdrawn SRFI 102 routines are built from the primitives suggested by Arthur A. Gleckler.
• The author is not a fan of this withdrawn SRFI but it is an interesting exercise.

## Bugs and Limitations

• When no lambda-info is available no arity info is available.
• When a source is compiled with '-no-lambda-info' no arity info is available.
• Anonymous, Composed & Curried procedures must have an explicitly set arity.
• Support for case-lambda and match-lambda is not automatic.

Kon Lovett

## Version history

1.0.3
Use compiled setup-helper.
1.0.2
1.0.1
1.0.0
Initial Chicken 4 release.