author | Claus Gittinger <cg@exept.de> |
Tue, 23 Apr 1996 16:54:20 +0200 | |
changeset 1270 | 4e8058487ed3 |
parent 1269 | 77682b54144c |
child 1293 | 02fb05148c98 |
permissions | -rw-r--r-- |
96 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
344 | 3 |
All Rights Reserved |
96 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Message subclass:#MessageSend |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
14 |
instanceVariableNames:'receiver' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
15 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
16 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
17 |
category:'Kernel-Methods' |
96 | 18 |
! |
19 |
||
20 |
!MessageSend class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
344 | 25 |
All Rights Reserved |
96 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
Instances of MessageSend can be used for simulation programs. |
|
39 |
They keep some receiver, selector and arguments and can be evaluated |
|
1269 | 40 |
at any time later. (basically, they are like MessageObjects, but keep |
41 |
the receiver in addition to the selector & arguments). |
|
42 |
||
96 | 43 |
They can also be used as replacement for simple [self foo]-blocks. |
44 |
Of course, they could also be replaced by blocks such as |
|
45 |
'[receiver perform:selector withArguments:arguments]', |
|
344 | 46 |
but blocks are somewhat more expensive in their creation and require |
47 |
more storage. |
|
48 |
||
1269 | 49 |
If you plan to write a simulator and want to queue cillions of blocks, |
50 |
try to use MessageSends instead of blocks |
|
51 |
(or even: message, if the receiver is constant); |
|
52 |
this will save you a lot of memory. |
|
53 |
||
96 | 54 |
However, the send-operation itself is faster in a block, since it |
55 |
will use a better caching scheme (inline-cache) for its send, while |
|
56 |
sending here is done with a #perform:, which is not inline-cached. |
|
1269 | 57 |
Also, blocks are more flexible, in that they allow access to local |
58 |
variables of the defining method - and work without a need to define an |
|
59 |
extra visited method (read literature on visitor patterns). |
|
60 |
||
363 | 61 |
Thus it is not sure, which one is actually better to use ... |
62 |
||
63 |
You can either store arguments in the messageSend object, or |
|
64 |
leave them undefined until the send is actually performed, and |
|
65 |
pass any arguments with the value:-messages. |
|
1270 | 66 |
|
67 |
[See also:] |
|
68 |
Block Message |
|
1269 | 69 |
" |
70 |
! |
|
96 | 71 |
|
1269 | 72 |
examples |
73 |
" |
|
96 | 74 |
Example: |
75 |
||
76 |
|m| |
|
77 |
||
78 |
m := MessageSend receiver:1 selector:#+ arguments:#(2). |
|
363 | 79 |
m value. |
96 | 80 |
|
1269 | 81 |
is almost the same as: |
344 | 82 |
|
83 |
|m| |
|
84 |
||
85 |
m := [1+2]. |
|
363 | 86 |
m value. |
344 | 87 |
|
88 |
||
1269 | 89 |
|
96 | 90 |
Example2 (a simulation) |
1269 | 91 |
|q| |
96 | 92 |
|
1269 | 93 |
q := Queue new. |
94 |
... |
|
95 |
'put some action into the queue' |
|
96 |
q nextPut:(MessageSend receiver:someone selector:#foo arguments:#(). |
|
97 |
... |
|
98 |
'evaluate next action from the queue' |
|
99 |
q next value |
|
100 |
... |
|
344 | 101 |
|
102 |
if all sends are going to the same receiver, use: |
|
1269 | 103 |
|q| |
344 | 104 |
|
1269 | 105 |
q := Queue new. |
106 |
... |
|
107 |
'put some action into the queue' |
|
108 |
q nextPut:(Message selector:#foo arguments:#(). |
|
109 |
... |
|
110 |
'evaluate next action from the queue' |
|
111 |
q next sendTo:someone |
|
112 |
... |
|
96 | 113 |
" |
1269 | 114 |
|
96 | 115 |
! ! |
116 |
||
117 |
!MessageSend class methodsFor:'instance creation'! |
|
118 |
||
119 |
receiver:r selector:sel arguments:argArray |
|
1269 | 120 |
"create & return a new instance which can be used to |
121 |
send sel with arguments to some receiver, r" |
|
122 |
||
96 | 123 |
|newMessage| |
124 |
||
344 | 125 |
newMessage := super new setSelector:sel arguments:argArray. |
96 | 126 |
newMessage receiver:r. |
127 |
^ newMessage |
|
1269 | 128 |
|
129 |
"Modified: 23.4.1996 / 16:52:33 / cg" |
|
96 | 130 |
! ! |
131 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
132 |
!MessageSend methodsFor:'accessing'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
133 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
134 |
numArgs |
1269 | 135 |
"return the number of arguments of the message" |
136 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
137 |
^ selector numArgs |
1269 | 138 |
|
139 |
"Modified: 23.4.1996 / 16:52:51 / cg" |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
140 |
! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
141 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
142 |
receiver |
1269 | 143 |
"return the receiver of the message" |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
144 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
145 |
^ receiver |
1269 | 146 |
|
147 |
"Modified: 23.4.1996 / 16:52:59 / cg" |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
148 |
! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
149 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
150 |
receiver:r |
1269 | 151 |
"set the receiver of the message" |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
152 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
153 |
receiver := r |
1269 | 154 |
|
155 |
"Modified: 23.4.1996 / 16:53:04 / cg" |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
156 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
157 |
|
96 | 158 |
!MessageSend methodsFor:'evaluation'! |
159 |
||
160 |
value |
|
160 | 161 |
"evaluate the messagesend with the original arguments" |
96 | 162 |
|
163 |
^ receiver perform:selector withArguments:args |
|
164 |
! |
|
165 |
||
166 |
value:someArgument |
|
167 |
"evaluate the messagesend, with someArgument instead of the original" |
|
168 |
||
169 |
^ receiver perform:selector with:someArgument |
|
170 |
! |
|
171 |
||
172 |
value:arg1 value:arg2 |
|
160 | 173 |
"evaluate the messagesend, with arg1 and arg2 instead of the original |
174 |
arguments" |
|
96 | 175 |
|
176 |
^ receiver perform:selector with:arg1 with:arg2 |
|
177 |
! |
|
178 |
||
179 |
value:arg1 value:arg2 value:arg3 |
|
160 | 180 |
"evaluate the messagesend, with arg1, arg2 and arg3 instead of the original |
181 |
arguments" |
|
96 | 182 |
|
183 |
^ receiver perform:selector with:arg1 with:arg2 with:arg3 |
|
363 | 184 |
! |
185 |
||
186 |
valueWithArguments:argArray |
|
187 |
"evaluate the messagesend, with arguments taken from argArray, |
|
188 |
instead of the original arguments" |
|
189 |
||
190 |
^ receiver perform:selector withArguments:argArray |
|
96 | 191 |
! ! |
192 |
||
193 |
!MessageSend methodsFor:'printing & storing'! |
|
194 |
||
195 |
displayString |
|
196 |
"return a string for display in inspectors etc." |
|
197 |
||
198 |
^ 'MessageSend(' , receiver displayString , '>>' , selector , ')' |
|
199 |
! |
|
200 |
||
201 |
printOn:aStream |
|
1269 | 202 |
"append a printed representation of the receiver to aStream" |
96 | 203 |
|
204 |
receiver printOn:aStream. |
|
205 |
aStream nextPutAll:'>>'. |
|
206 |
selector printOn:aStream |
|
1269 | 207 |
|
208 |
"Modified: 23.4.1996 / 16:53:35 / cg" |
|
96 | 209 |
! ! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
210 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
211 |
!MessageSend class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
212 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
213 |
version |
1270 | 214 |
^ '$Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.10 1996-04-23 14:54:20 cg Exp $' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
215 |
! ! |