eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MessageSend':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MessageSend


Inheritance:

   Object
   |
   +--Message
      |
      +--MessageSend
         |
         +--Event
         |
         +--MessageChannel

Package:
stx:libbasic
Category:
Kernel-Methods
Version:
rev: 1.37 date: 2024/02/09 11:31:40
user: stefan
file: MessageSend.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


Instances of MessageSend can be used for simulation programs.
They keep some receiver, selector and arguments and can be evaluated
at any time later. (basically, they are like MessageObjects, but keep
the receiver in addition to the selector & arguments).

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 require
more storage.

If you plan to write a simulator and want to queue cillions of blocks,
try to use MessageSends instead of blocks
(or even: message, if the receiver is constant);
this will save you a lot of memory.

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. 
Also, blocks are more flexible, in that they allow access to local
variables of the defining method - and work without a need to define an
extra visited method (read literature on visitor patterns).

Thus it is not sure, which one is actually better to use ...

You can either store arguments in the messageSend object, or
leave them undefined until the send is actually performed, and
pass any arguments with the value:-messages.

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.

Class protocol:

instance creation
o  receiver: r selector: sel
create & return a new instance which can be used to
send sel to some receiver, r

Usage example(s):

     (MessageSend receiver:nil selector:#foo) value

o  receiver: r selector: sel argument: something
create & return a new instance which can be used to
send sel with arguments to some receiver, r

Usage example(s):

     (MessageSend receiver:nil selector:#foo: argument:1) value

o  receiver: r selector: sel arguments: argArray
create & return a new instance which can be used to
send sel with arguments to some receiver, r

Usage example(s):

     (MessageSend receiver:nil selector:#foo: arguments:#(1)) value


Instance protocol:

Compatibility-Squeak
o  cull: optionalFirstArg
activate the receiver with one or zero arguments.
Squeak compatibility, but also present in VW Smalltalk

o  cull: optionalFirstArg cull: optionalSecondArg
activate the receiver with two or less arguments.
Squeak compatibility, but also present in VW Smalltalk

o  cull: firstArg cull: optionalSecondArg cull: optionalThirdArg
activate the receiver with three or less arguments.
Squeak compatibility, but also present in VW Smalltalk

Compatibility-V'Age
o  evaluate

o  evaluateWith: someArgument

o  evaluateWithArguments: argArray

accessing
o  argumentCount
VisualAge/ANSI compatibility: return the number of arguments of the message

o  numArgs
marked as obsolete by Stefan Vogel at 9-Feb-2024

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  receiver
return the receiver of the message

o  receiver: r
set the receiver of the message

evaluation
o  ensure: aBlock
block compatibility

o  ifCurtailed: aBlock
block compatibility

o  value
evaluate the messagesend with the original arguments

o  value: someArgument
evaluate the messagesend, with someArgument instead of the original

o  value: arg1 value: arg2
evaluate the messagesend, with arg1 and arg2 instead of the original
arguments

o  value: arg1 value: arg2 value: arg3
evaluate the messagesend, with arg1, arg2 and arg3 instead of the original
arguments

o  valueWithArguments: argArray
evaluate the messagesend, with arguments taken from argArray,
instead of the original arguments

o  valueWithOptionalArgument: arg
evaluate the messagesend.
Optionally pass an argument (if the selector is for a one arg message).

o  valueWithOptionalArgument: arg1 and: arg2
evaluate the messagesend.
Optionally pass up to two arguments.

printing & storing
o  displayOn: aGCOrStream
Compatibility
append a printed desription on some stream (Dolphin, Squeak)
OR:
display the receiver in a graphicsContext at 0@0 (ST80).
This method allows for any object to be displayed in some view
(although the fallBack is to display its printString ...)

o  printOn: aStream
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

testing
o  isBlockOrMessageSend


Examples:


Example:
   |m|

   m := MessageSend receiver:1 selector:#+ arguments:#(2).
   m value. 



is almost the same as:
   |m|

   m := [1+2].
   m value. 



Example2 (a simulation)
    |q|

    q := Queue new.
    ...
    'put some action into the queue'
    q nextPut:(MessageSend receiver:someone selector:#foo arguments:#().
    ...
    'evaluate next action from the queue'
    q next value
    ...

if all sends are going to the same receiver, use:
    |q|

    q := Queue new.
    ...
    'put some action into the queue'
    q nextPut:(Message selector:#foo arguments:#().
    ...
    'evaluate next action from the queue'
    q next sendTo:someone
    ...


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 02:25:37 GMT