next up previous
Next: Moving on Up: Getting Started Previous: Run the Hello

Understanding the program

This very simple program defines a function called ``doit'', which takes no parameters, and returns a unit result.

The body of the function calls a service routine called ``print''. The print routine takes a single argument, which is the datum to print. The second print call is invoked on a string, while the first argument is yet another service routine call; the ``thisHost'' service routine returns a value of type host which is a representation of the active router that the program is currently executing on.

  
Figure 1: The PLAN network environment

To illustrate how the print routine is working, let us briefly look at how PLAN programs are injected by a host into the active network, and how the host obtains their output. Figure 1 illustrates a hypothetical active network and a host with an application that desires to inject a PLAN program into that network. To do this, the application opens a connection to the local PLAN interpreter, and constructs and submits a PLAN packet via this connection. The PLAN packet contains the PLAN code to execute, which in our example is the ``Hello World'' code, as well some other things that we need not worry about yet. This connection also serves to pass output from the PLAN program back to the host. It is via this connection that PLANStart receives the output generated by the print command, and it is PLANStart that displays this output on your screen.

In PLAN, this connection is referred to as a port. Ports are duplex connections between host applications and active routers. The active router side of the port always receives PLAN packets, while the application side receives output in a number of formats, depending on the service command used; for the print routine, the output format is a string. When a PLAN packet is first injected into the network onto a particular node, it is associated with its injection port on that node. That way, output routines such as print have a default port upon which to send their output. These routines will only work on the injection node, because that is where the port resides. For example, in Figure 1, the PLAN program in the packet submitted by myhost will have its print output sent back to myhost via the injection port so long as it is executing on myhost. If the program were to move to another node and then execute the print routine, an exception would be raised.

For a precise description of what the various service routines do, and a greater exposition on ports, please refer to the PLAN Programmer's Guide [3].



next up previous
Next: Moving on Up: Getting Started Previous: Run the Hello



Michael Hicks
Mon Nov 24 10:50:43 EST 1997