Why is this peace of code is valid?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is this peace of code is valid?

Günther Schmidt
Hi,

can anybody please explain to me why this code is valid?


acceptanceMonitor completionBlock:
        [:socket |
            serverMonitor := BlockingCallMonitor new.
            serverMonitor callBlock: [Compiler evaluate: socket receive logged:
false].
     serverMonitor completionBlock: [:answer | socket send: answer].
     serverMonitor errorBlock: [:error | Sound beep. serverMonitor
terminate].
     serverMonitor monitor ].


I'm referring to the "serverMonitor" temp variable, how come it doesn't
have to be " [:socket || serverMonitor | ....]"?

If I again missed the obvious at least this time I've got a good excuse,
I'm recovering from the flu.

Günther

PS the sample above is copied from an object arts TCP/IP sockets sample.

http://www.object-arts.com/Lib/EducationCentre4/htm/monitoringblockingcalls.htm


Reply | Threaded
Open this post in threaded view
|

Re: Why is this peace of code is valid?

Ian Bartholomew-19
Günther,

> anybody please explain to me why this code is valid?

Because it's intended to be compiled and evaluated in a workspace.  Dolphin
workspaces will automatically, and silently, create any undefined temporary
variables for you within the context of the workspace evaluation.  In your
example you can imagine Dolphin inserting a

| serverMonitor |

before the start of the code.  You can inspect all workspaces variables
using the "Workspace/Variables" menu option.

When you use the examples to create "proper" code you will have to add the
declarations yourself, in the appropriate places.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.