MessageSend.st
author claus
Mon, 10 Oct 1994 01:53:52 +0100
changeset 160 5dae57a490bd
parent 96 4da5558d8141
child 344 4b35f99afefb
permissions -rw-r--r--
*** empty log message ***

"
 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.2 1994-10-10 00:53:52 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.2 1994-10-10 00:53:52 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. 
    Thus it is not sure, which one is faster in the end ...

    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 setSelector:sel arguments:argArray.
    newMessage receiver:r.
    ^ newMessage
! !

!MessageSend methodsFor:'evaluation'!

value
    "evaluate the messagesend with the original arguments"

    ^ 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
     arguments"

    ^  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
     arguments"

    ^  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
! !