Electric Communities: E Programming Language 

Hello EWhen Inverse

The Hello EWhen Inverse tutorial demonstrates how you can use the ewhen statement to choose when you want to reveal your information, perhaps after specified criteria have been met.

You can use ewhen to impose the order in which code executes. This is useful in situations like writing online games, where multiple players are rolling a dice and you want to generate a random result (rather than an influenced one).

Hello ewhen inverse

To run this tutorial, enter the following code and study the walkthrough that accompanies it. This example is also available in the online example suite as HelloEWhenInv.e

  Another ewhen tutorial, in this case we pass 
  an unforwarded E object reference and then forward it.
  Copyright 1996 Electric Communities, all rights reserved.

  Program output:

  Sent StartHelloEWhenInstance
  In HelloEWhenInvObj after forward
  In HelloEWhenInvObj2
  Hello World with 7

import ec.e.lang.EInteger;

public class HelloEWhenInv
  public static void main(String args[]) {  
    HelloEWhenInvObj theInstance = 
      new HelloEWhenInvObj();
    theInstance <- StartHelloEWhenInstance();
    System.out.println("Sent StartHelloEWhenInstance");

eclass HelloEWhenInvObj
  EInteger anEInteger;
  emethod StartHelloEWhenInstance() {
    HelloEWhenInvObj2 first = new HelloEWhenInvObj2();
    first <- hello(anEInteger);
    &anEInteger <- forward ((new EInteger(7)) );
    System.out.println("In HelloEWhenInvObj after forward");

eclass HelloEWhenInvObj2 
  emethod hello(EInteger putEIntHere) {
    System.out.println("In HelloEWhenInvObj2");
    ewhen putEIntHere (int thisInt) ) {
      System.out.println("Hello World with " + thisInt);

The Walkthrough

  1. main instantiates the E-object theInstance, an instance of the E-class HelloEWhenInvObj.
  2. main sends the message StartHelloEWhenInstance to theInstance.
  3. theInstance executes the HelloEWhenInvObj E-method StartHelloEWhenInstance to handle the message.
  4. StartHelloEWhenInstance instantiates the E-object first, an instance of the E-class HelloEWhenInvObj2.
  5. StartHelloEWhenInstance sends the message hello to first, passing as an argument the uninitialized instance variable anEInteger.
  6. first executes the HelloEWhenInvObj2 E-method hello to handle the message.
  7. hello executes an ewhen statement that says, ``When you get a value for the argument you were passed, assign it to thisInt, and execute the following code block.'' hello waits for the value to be defined.
  8. Meanwhile, StartHelloEWhenInstance instantiates a new EInteger with a value of 7 and forwards the channel referred to by the distributor &anEInteger to point to this value. anEInteger is now defined.
  9. hello's ewhen statement detects that the argument it was passed is now defined, assigns its value to thisInt, and prints out, ``Hello World with 7''.

Compiling and Running

To compile source code for the E runtime, use the ecomp compiler:

  ecomp filename

The ecomp command compiles E and Java source files directly into Java bytecodes. You can then run your compiled program with the E Java interpreter (the javaec command):

  javaec filename

For more information on these commands, see the E Tools and Utilities section in the E Programmer's Guide.

Copyright (c) 1996 Electric Communities. All rights reserved worldwide.
Most recent update: 5/29/96