Contents Home Page
This chapter discusses the following topics:
How to install and set up E
E syntax and terminology
General principles for programming E applications
You can download the E extensions from the Electric Communities website, http://www.communities.com. For installation and configuration instructions, see the online README.TXT file. For information on last minute updates to E, see the online RELEASE.TXT file. All the documentation for the E extensions (including this tutorial) is also available online, both in HTML and postscript format.
This section describes basic E syntax and terminology, including the following concepts:
- Channel
- Distributor
- E-class
- E-method
- einterface
- E-send
- eif
- ewhen
For more detailed information on these concepts, see the Glossary, and also the E Programmer's Manual.
In E, objects send messages to other objects, either on the same or on a remote machine. As you would send a message to a friend across town or across the country, and have a reasonable expectation that your friend would be the person to receive it (instead of their entire neighborhood), so E-objects send specific messages to each other. An E-object can be any of three things:
- A Channel. This is conduit object that channels a message from one object to another, without ever understanding or handling the message. A channel serves as a placeholder for any values that the recipient object may furnish.You can only send messages through channels, not to them. A channel is directed to a specific destination using its associated distributor.
When the message contains a request for some value to be supplied by the receiving object, a channel back to the sending object is included as one of the message parameters. This is like the concept of a self addressed stamped envelope.
- A Distributor. This is an object that points the message to the intended receiving object or objects. It's like a one way nozzle on the end of a channel; you can spray the messages out, but you can't reverse the flow. A distributor is associated only with a channel. You send a forward message to the distributor that tells it where to direct the channel (that is, what object is going to receive the message). You can forward messages to one or many destinations at once (known as a multicast) which lets you send a single message to several objects simultaneously. When a multicast is specified, there is still only one channel and one distributor.
If you want to send a message to a distributor (for example, in order to send it a forward message) you use the distributor operator, which is the ampersand (&). This operator lets you interact with the distributor as an E-class.
- A value. An E-object can have either its own or another object's value.
E-classes receive a given message by using E-methods. An E-method is a block of code invoked when the E-object receives a message of the given E-method name. E-methods never return values because of the nature of E. The only ways to receive a requested value is through channels and distributors, and through deferring statements such as ewhen and eif ( mentioned in the following paragraphs).
You define an E-method using the keyword emethod. Unlike a Java method, an E-method creates a private void method, and is not directly accessible with normal Java programming techniques.
To send a message, you use the send operator, which is the left arrow symbol (<-). In Java, you call a method and wait until a message arrives. In E, you send your message and forget about it, assuming that the message will arrive and be acted upon.
The ewhen and eif statements defer execution of their associated code block until a value has been furnished for an expression. You use ewhen and eif to enforce security, to obtain values from other E-objects, and to bind Java and E. As you go through the tutorials, you'll see how this is done.
- ewhen is an unconditional statement: "When I have x, unconditionally do y."
- eif is a conditional statement: "When I have x, If x is true, do this, if x is false, do that."
If you want to send a message to a distributor (for example, in order to send it a forward message) you use the distributor operator, which is the ampersand (&). This operator lets you interact with the distributor as an E-class.
You'll find these guidelines repeated in more detail in the E Programmer's Manual,, but they are important concepts to remember when programming in E and are worth reviewing here. If you are already comfortable with the concept of writing code with optimistic computation in mind, you can skip this section.
- Write your code as if you already have the answers. This means writing your code as if you already have all the values you need for computation.
- Create message protocols that deliver the values you need. Set up channels (usually unforwarded at this stage) and distributors to move this information when it becomes available. This code goes at the beginning.
- Write ewhen and eif statements for each value that you assumed you had in step 1. These statements follow the protocols and encompasses the body of code you wrote in step 1. They enforce security by insuring that the code which uses a value you assumed does not get executed until after it actually gets that value.
- For each value for which you initially provided an unforwarded channel, write a forward statement that will deliver the value at the time you specify.