You are looking at historical revision 28453 of this page. It may differ significantly from its current revision.
Procedure Arity Inspection
- Bugs and Limitations
- Version history
From the Draft SRFI 102.
This implementation uses the Chicken procedure-information facility.
SRFI 102 (Draft)
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.
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.
- scalar arity-at-least-object
append-procedure-arity![procedure] (append-procedure-arity! PROCEDURE A | K)
PROCEDURE has arity information from an A or K.
- scalar arity-at-least-object
- See the "run.scm" test source.
- 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 draft SRFI 102 routines are built from the primitives suggested by Arthur A. Gleckler.
- The author is not a fan of this SRFI (draft!) 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.
- Use compiled setup-helper.
- Initial Chicken 4 release.
From the Draft SRFI 102 Document Copyright (C) David Van Horn 2009. All Rights Reserved.
Copyright (C) 2009 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.