|
Smalltalk/X WebserverDocumentation of class 'MessageSend': |
|
|
Class: MessageSendInheritance:Object | +--Message | +--MessageSend | +--Event
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. Related information:
Block
Message
Class protocol:instance creation
Instance protocol:accessing
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 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 20:02:46 GMT
|