1 | [[tags: egg]] |
---|
2 | |
---|
3 | == srfi-102 |
---|
4 | |
---|
5 | Procedure Arity Inspection |
---|
6 | |
---|
7 | [[toc:]] |
---|
8 | |
---|
9 | |
---|
10 | == Documentation |
---|
11 | |
---|
12 | From the Draft [[http://srfi.schemers.org/srfi-102/srfi-102.html|SRFI 102]]. |
---|
13 | |
---|
14 | This implementation uses the Chicken {{procedure-information}} facility. |
---|
15 | |
---|
16 | === SRFI 102 (''Withdrawn: 2013/02/24'') |
---|
17 | |
---|
18 | ==== procedure-arity |
---|
19 | |
---|
20 | <procedure>(procedure-arity PROCEDURE) => ARITY-OBJECT</procedure> |
---|
21 | |
---|
22 | Produces an {{arity-object}} representing the arity of {{PROCEDURE}}. If {{#f}} |
---|
23 | results, no information is available for {{PROCEDURE}}. |
---|
24 | |
---|
25 | If this procedure produces an {{exact-non-negative-integer}}, {{K}}, then |
---|
26 | {{PROCEDURE}} accepts exactly {{K}} arguments; applying {{PROCEDURE}} to some |
---|
27 | number of arguments other than {{K}} will result in an arity error. |
---|
28 | |
---|
29 | If this procedure produces an {{arity-at-least-object}}, {{A}}, then |
---|
30 | {{PROCEDURE}} accepts {{(arity-at-least-value A)}} or more arguments; applying |
---|
31 | {{PROCEDURE}} to some number of arguments less than {{(arity-at-least-value |
---|
32 | A)}} will result in an arity error. |
---|
33 | |
---|
34 | If this procedure produces a {{list}}, then {{PROCEDURE}} accepts any of the |
---|
35 | arities described by the elements of the list; applying {{PROCEDURE}} to some |
---|
36 | number of arguments not described by an element of the list will result in an |
---|
37 | arity error. |
---|
38 | |
---|
39 | ==== procedure-arity-includes? |
---|
40 | |
---|
41 | <procedure>(procedure-arity-includes? PROCEDURE K) => BOOLEAN</procedure> |
---|
42 | |
---|
43 | Returns {{#t}} if the {{PROCEDURE}} can accept {{K}} arguments and {{#f}} |
---|
44 | otherwise. If this procedure returns {{#f}}, applying {{PROCEDURE}} to {{K}} |
---|
45 | arguments will result in an arity error. |
---|
46 | |
---|
47 | ==== arity-at-least? |
---|
48 | |
---|
49 | <procedure>(arity-at-least? OBJECT) => BOOLEAN</procedure> |
---|
50 | |
---|
51 | Returns {{#t}} if {{OBJECT}} is an {{arity-at-least-object}} and {{#f}} |
---|
52 | otherwise. |
---|
53 | |
---|
54 | ==== arity-at-least-value |
---|
55 | |
---|
56 | <procedure>(arity-at-least-value A) => INTEGER</procedure> |
---|
57 | |
---|
58 | Returns the {{exact-non-negative-integer}} denoting the minimum number of |
---|
59 | arguments required by the given {{A}}. |
---|
60 | |
---|
61 | === Extensions |
---|
62 | |
---|
63 | ==== fixed-arity->arity-at-least |
---|
64 | |
---|
65 | <procedure>(fixed-arity->arity-at-least K) => ARITY-AT-LEAST-OBJECT</procedure> |
---|
66 | |
---|
67 | Returns a scalar {{arity-at-least-object}} for the supplied |
---|
68 | {{exact-non-negative-integer}} {{K}}. |
---|
69 | |
---|
70 | ==== procedure-arity-available? |
---|
71 | |
---|
72 | <procedure>(procedure-arity-available? PROCEDURE) => BOOLEAN</procedure> |
---|
73 | |
---|
74 | Returns {{#t}} if the {{PROCEDURE}} has arity information. |
---|
75 | |
---|
76 | ==== procedure-fixed-arity? |
---|
77 | |
---|
78 | <procedure>(procedure-fixed-arity? PROCEDURE) => BOOLEAN</procedure> |
---|
79 | |
---|
80 | Returns {{#t}} if the {{PROCEDURE}} accepts only a fixed number of arguments. |
---|
81 | |
---|
82 | ==== procedure-minimum-arity |
---|
83 | |
---|
84 | <procedure>(procedure-minimum-arity PROCEDURE) => INTEGER</procedure> |
---|
85 | |
---|
86 | Returns the minimum number of arguments acceptable by the {{PROCEDURE}}. |
---|
87 | |
---|
88 | ==== procedure-arity-set! |
---|
89 | |
---|
90 | <procedure>(procedure-arity-set! PROCEDURE [A | K] ...)</procedure> |
---|
91 | |
---|
92 | {{PROCEDURE}} has arity information from one or more {{A}} or {{K}}. |
---|
93 | |
---|
94 | ; {{K}} : {{exact-non-negative-integer}} |
---|
95 | |
---|
96 | ; {{A}} : scalar {{arity-at-least-object}} |
---|
97 | |
---|
98 | ==== append-procedure-arity! |
---|
99 | |
---|
100 | <procedure>(append-procedure-arity! PROCEDURE A | K)</procedure> |
---|
101 | |
---|
102 | {{PROCEDURE}} has arity information from an {{A}} or {{K}}. |
---|
103 | |
---|
104 | ; {{K}} : {{exact-non-negative-integer}} |
---|
105 | |
---|
106 | ; {{A}} : scalar {{arity-at-least-object}} |
---|
107 | |
---|
108 | |
---|
109 | == Usage |
---|
110 | |
---|
111 | <enscript language=scheme> |
---|
112 | (require-extension srfi-102) |
---|
113 | </enscript> |
---|
114 | |
---|
115 | |
---|
116 | == Examples |
---|
117 | |
---|
118 | * See the "run.scm" test source. |
---|
119 | |
---|
120 | |
---|
121 | == Notes |
---|
122 | |
---|
123 | * To call this a ''work in progress'' is an understatement. The pulling of |
---|
124 | procedure arity & name from the {{lambda-info}} type is a hack. |
---|
125 | |
---|
126 | * The module {{procedure-introspection}} provides the routines for this |
---|
127 | extension. |
---|
128 | |
---|
129 | * The draft SRFI 102 routines are built from the primitives suggested by Arthur |
---|
130 | A. Gleckler. |
---|
131 | |
---|
132 | * The author is not a fan of this SRFI (draft!) but it is an interesting |
---|
133 | exercise. |
---|
134 | |
---|
135 | |
---|
136 | == Requirements |
---|
137 | |
---|
138 | |
---|
139 | == Bugs and Limitations |
---|
140 | |
---|
141 | * When no {{lambda-info}} is available no arity info is available. |
---|
142 | |
---|
143 | * When a source is compiled with '-no-lambda-info' no arity info is available. |
---|
144 | |
---|
145 | * Anonymous, Composed & Curried procedures must have an explicitly set arity. |
---|
146 | |
---|
147 | * Support for {{case-lambda}} and {{match-lambda}} is not automatic. |
---|
148 | |
---|
149 | |
---|
150 | == Author |
---|
151 | |
---|
152 | [[/users/kon-lovett|Kon Lovett]] |
---|
153 | |
---|
154 | |
---|
155 | == Version history |
---|
156 | |
---|
157 | ; 1.0.3 : Use compiled setup-helper. |
---|
158 | ; 1.0.2 : |
---|
159 | ; 1.0.1 : |
---|
160 | ; 1.0.0 : Initial Chicken 4 release. |
---|
161 | |
---|
162 | |
---|
163 | == License |
---|
164 | |
---|
165 | From the Draft SRFI 102 Document Copyright (C) David Van Horn 2009. All Rights |
---|
166 | Reserved. |
---|
167 | |
---|
168 | Copyright (C) 2009 Kon Lovett. All rights reserved. |
---|
169 | |
---|
170 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
---|
171 | this software and associated documentation files (the Software), to deal in the |
---|
172 | Software without restriction, including without limitation the rights to use, |
---|
173 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
---|
174 | Software, and to permit persons to whom the Software is furnished to do so, |
---|
175 | subject to the following conditions: |
---|
176 | |
---|
177 | The above copyright notice and this permission notice shall be included in all |
---|
178 | copies or substantial portions of the Software. |
---|
179 | |
---|
180 | THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
181 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
182 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
183 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
184 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
185 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
---|
186 | SOFTWARE. |
---|