MessageSend.st
changeset 96 4da5558d8141
child 160 5dae57a490bd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MessageSend.st	Fri Aug 05 03:06:59 1994 +0200
@@ -0,0 +1,148 @@
+"
+ COPYRIGHT (c) 1994 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+Message subclass:#MessageSend
+         instanceVariableNames:'receiver'
+         classVariableNames:''
+         poolDictionaries:''
+         category:'Kernel-Methods'
+!
+
+MessageSend comment:'
+COPYRIGHT (c) 1994 by Claus Gittinger
+              All Rights Reserved
+
+$Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.1 1994-08-05 01:06:59 claus Exp $
+'!
+
+!MessageSend class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1994 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.1 1994-08-05 01:06:59 claus Exp $
+"
+!
+
+documentation
+"
+    Instances of MessageSend can be used for simulation programs.
+    They keep some receiver, selector and arguments and can be evaluated
+    at any time later.
+    They can also be used as replacement for simple [self foo]-blocks.
+    Of course, they could also be replaced by blocks such as
+    '[receiver perform:selector withArguments:arguments]', 
+    but blocks are somewhat more expensive in their creation and use.
+    However, the send-operation itself is faster in a block, since it
+    will use a better caching scheme (inline-cache) for its send, while
+    sending here is done with a #perform:, which is not inline-cached. 
+
+    Example:
+
+       |m|
+
+       m := MessageSend receiver:1 selector:#+ arguments:#(2).
+       m value.
+
+    Example2 (a simulation)
+	|q|
+
+	q := Queue new.
+	...
+	'put some action into the queue'
+	q nextPut:(MessageSend receiver:something selector:#foo arguments:#().
+	...
+	'evaluate next action from the queue'
+	q next value
+	...
+"
+! !
+
+!MessageSend class methodsFor:'instance creation'!
+
+receiver:r selector:sel arguments:argArray
+    |newMessage|
+
+    newMessage := super selector:sel arguments:argArray.
+    newMessage receiver:r.
+    ^ newMessage
+! !
+
+!MessageSend methodsFor:'evaluation'!
+
+value
+    "evaluate the messagesend"
+
+    ^ receiver perform:selector withArguments:args
+!
+
+value:someArgument
+    "evaluate the messagesend, with someArgument instead of the original"
+ 
+    ^ receiver perform:selector with:someArgument
+!
+
+value:arg1 value:arg2
+    "evaluate the messagesend, with arg1 and arg2 instead of the original"
+
+    ^  receiver perform:selector with:arg1 with:arg2
+!
+
+value:arg1 value:arg2 value:arg3
+    "evaluate the messagesend, with arg1, arg2 and arg3 instead of the original"
+
+    ^  receiver perform:selector with:arg1 with:arg2 with:arg3
+! !
+
+!MessageSend methodsFor:'accessing'!
+
+receiver:r
+    "set the receiver"
+
+    receiver := r
+!
+
+receiver
+    "return the receiver"
+
+    ^ receiver
+! !
+
+!MessageSend methodsFor:'printing & storing'!
+
+displayString
+    "return a string for display in inspectors etc."
+
+    ^ 'MessageSend(' , receiver displayString , '>>' , selector , ')'
+!
+
+printOn:aStream
+    "return a string for printing the receiver"
+
+    receiver printOn:aStream.
+    aStream nextPutAll:'>>'.
+    selector printOn:aStream
+! !
+