2239
|
1 |
Block subclass:#VarArgBlock
|
|
2 |
instanceVariableNames:''
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Kernel-Methods'
|
|
6 |
!
|
|
7 |
|
|
8 |
!VarArgBlock class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
copyright
|
|
11 |
"
|
|
12 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
|
|
13 |
All Rights Reserved
|
|
14 |
|
|
15 |
This software is furnished under a license and may be used
|
|
16 |
only in accordance with the terms of that license and with the
|
|
17 |
inclusion of the above copyright notice. This software may not
|
|
18 |
be provided or otherwise made available to, or used by, any
|
|
19 |
other person. No title to or ownership of the software is
|
|
20 |
hereby transferred.
|
|
21 |
"
|
|
22 |
|
|
23 |
|
|
24 |
!
|
|
25 |
|
|
26 |
documentation
|
|
27 |
"
|
|
28 |
VarArgBlocks are much like blocks, but can accept a variable
|
|
29 |
number of arguments. They must be defined as a regular block,
|
|
30 |
with 1 argument. When executed, the actual argument list is
|
|
31 |
passed in that single argument (as a collection).
|
|
32 |
|
|
33 |
Create a variableArgument block by sending #varArgs to a regular
|
|
34 |
block.
|
|
35 |
|
|
36 |
[author:]
|
|
37 |
Claus Gittinger
|
|
38 |
|
|
39 |
[see also:]
|
|
40 |
Block
|
|
41 |
"
|
|
42 |
|
|
43 |
!
|
|
44 |
|
|
45 |
examples
|
|
46 |
"
|
|
47 |
the same block, evaluated with 2 or 5 arguments:
|
|
48 |
[exBegin]
|
|
49 |
|b|
|
|
50 |
|
|
51 |
b := [:args | Transcript show:'wow: '; showCR:args] varArgs.
|
|
52 |
|
|
53 |
b value:'hi' value:'there'.
|
|
54 |
b value:'hello' value:'there' value:'how' value:'about' value:'this'.
|
|
55 |
[exEnd]
|
|
56 |
|
|
57 |
|
|
58 |
does it accept a variable number of arguments ?:
|
|
59 |
[exBegin]
|
|
60 |
|b|
|
|
61 |
|
|
62 |
b := [:args | Transcript showCR:args].
|
|
63 |
Transcript showCR:(b isVarArgBlock).
|
|
64 |
|
|
65 |
b := [:args | Transcript showCR:args] varArgs.
|
|
66 |
Transcript showCR:(b isVarArgBlock)
|
|
67 |
[exEnd]
|
|
68 |
"
|
|
69 |
|
|
70 |
"Created: 23.1.1997 / 04:57:26 / cg"
|
|
71 |
! !
|
|
72 |
|
|
73 |
!VarArgBlock methodsFor:'evaluation'!
|
|
74 |
|
|
75 |
value
|
|
76 |
"evaluate the receiver with no block args."
|
|
77 |
|
|
78 |
^ super value:#()
|
|
79 |
|
|
80 |
"Created: 23.1.1997 / 04:57:49 / cg"
|
|
81 |
!
|
|
82 |
|
|
83 |
value:arg
|
|
84 |
"evaluate the receiver with a single argument."
|
|
85 |
|
|
86 |
^ super value:(Array with:arg)
|
|
87 |
|
|
88 |
"Created: 23.1.1997 / 04:57:57 / cg"
|
|
89 |
!
|
|
90 |
|
|
91 |
value:arg1 value:arg2
|
|
92 |
"evaluate the receiver with two arguments."
|
|
93 |
|
|
94 |
^ super value:(Array with:arg1 with:arg2)
|
|
95 |
|
|
96 |
"Created: 23.1.1997 / 04:58:03 / cg"
|
|
97 |
!
|
|
98 |
|
|
99 |
value:arg1 value:arg2 value:arg3
|
|
100 |
"evaluate the receiver with three arguments."
|
|
101 |
|
|
102 |
^ super value:(Array with:arg1 with:arg2 with:arg3)
|
|
103 |
|
|
104 |
"Created: 23.1.1997 / 04:58:09 / cg"
|
|
105 |
!
|
|
106 |
|
|
107 |
value:arg1 value:arg2 value:arg3 value:arg4
|
|
108 |
"evaluate the receiver with four arguments."
|
|
109 |
|
|
110 |
^ super value:(Array
|
|
111 |
with:arg1
|
|
112 |
with:arg2
|
|
113 |
with:arg3
|
|
114 |
with:arg4)
|
|
115 |
|
|
116 |
"Modified: 22.1.1997 / 19:41:22 / cg"
|
|
117 |
"Created: 23.1.1997 / 04:58:14 / cg"
|
|
118 |
!
|
|
119 |
|
|
120 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5
|
|
121 |
"evaluate the receiver with five arguments."
|
|
122 |
|
|
123 |
^ super value:(Array
|
|
124 |
with:arg1
|
|
125 |
with:arg2
|
|
126 |
with:arg3
|
|
127 |
with:arg4
|
|
128 |
with:arg5)
|
|
129 |
|
|
130 |
"Modified: 22.1.1997 / 19:41:26 / cg"
|
|
131 |
"Created: 23.1.1997 / 04:58:18 / cg"
|
|
132 |
!
|
|
133 |
|
|
134 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6
|
|
135 |
"evaluate the receiver with six arguments."
|
|
136 |
|
|
137 |
^ super value:(Array
|
|
138 |
with:arg1
|
|
139 |
with:arg2
|
|
140 |
with:arg3
|
|
141 |
with:arg4
|
|
142 |
with:arg5
|
|
143 |
with:arg6)
|
|
144 |
|
|
145 |
"Modified: 22.1.1997 / 19:41:29 / cg"
|
|
146 |
"Created: 23.1.1997 / 04:58:22 / cg"
|
|
147 |
!
|
|
148 |
|
|
149 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7
|
|
150 |
"evaluate the receiver with seven arguments."
|
|
151 |
|
|
152 |
^ super value:(Array
|
|
153 |
with:arg1
|
|
154 |
with:arg2
|
|
155 |
with:arg3
|
|
156 |
with:arg4
|
|
157 |
with:arg5
|
|
158 |
with:arg6
|
|
159 |
with:arg7)
|
|
160 |
|
|
161 |
"Modified: 22.1.1997 / 19:41:33 / cg"
|
|
162 |
"Created: 23.1.1997 / 04:58:26 / cg"
|
|
163 |
!
|
|
164 |
|
|
165 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8
|
|
166 |
"evaluate the receiver with eight arguments."
|
|
167 |
|
|
168 |
^ super value:(Array
|
|
169 |
with:arg1
|
|
170 |
with:arg2
|
|
171 |
with:arg3
|
|
172 |
with:arg4
|
|
173 |
with:arg5
|
|
174 |
with:arg6
|
|
175 |
with:arg7
|
|
176 |
with:arg8)
|
|
177 |
|
|
178 |
"Created: 23.1.1997 / 04:58:30 / cg"
|
|
179 |
!
|
|
180 |
|
|
181 |
valueWithArguments:argArray
|
|
182 |
"evaluate the receiver with all arguments in argArray."
|
|
183 |
|
|
184 |
^ super value:argArray
|
|
185 |
|
|
186 |
"Created: 23.1.1997 / 04:59:16 / cg"
|
|
187 |
! !
|
|
188 |
|
|
189 |
!VarArgBlock methodsFor:'testing'!
|
|
190 |
|
|
191 |
isVarArgBlock
|
|
192 |
"return true, if this block accepts a variable number of arguments"
|
|
193 |
|
|
194 |
^ true
|
|
195 |
|
|
196 |
"Created: 23.1.1997 / 05:00:18 / cg"
|
|
197 |
! !
|
|
198 |
|
|
199 |
|