Walnut/Distributed Computing/Multiway when-catch

From Erights

Jump to: navigation, search


Multiway when-catch

If you need to resolve several references before making a computation, use a multiway when-catch, in which you specify several arguments in the structure:


 # E syntax
 def maxTempVow := vehicleSpecsRcvr <- getMaxEngineTemperature(carType)
 def engineTempVow := carRcvr <- getEngineTemperature()
 when (engineTempVow,maxTempVow) -> {
     if (engineTempVow > maxTempVow) {println("Car overheating!")}
 } catch e {println(`Lost car or vehicleSpecs: $e`)}

In this when-catch, since all the arguments are vows, the corresponding parameters (engineTemp and maxTemp, to the right of the "->") are simply local objects (integers in this case). How do we know that these integers will be local, not remote, even though we retrieved them from Rcvrs? Because integers are passed by construction, as discussed next.

Pass By Construction and Pass By Proxy, References Far and Near

In the above example, the temperature is an integer and is guaranteed to resolve to a local integer object upon which you can make immediate calls, even if the car is remote. Transparent immutable objects, such as integers, floating point numbers, booleans, strings, and the E data structures ConstLists and ConstMaps, are always passed by copy(which is the most common form of Pass By Construction), so you always get a local copy of the object on resolution if one of these is returned by a method call or send. This local copy can of course accept immediate calls.

Mutable objects, like the car in this example, reside on the machine upon which they were constructed. Such an object is passed by proxy. If such an object is on a different machine from the one on which your piece of the system is running, even when the promise resolves it will only resolve into a far reference (as opposed to a near reference for a local object). Far references accept eventual sends, but cannot accept immediate calls.

So in general, if you created the car using an eventual send to a possibly remote object (a receiver), you would probably have to interact with the car using eventual sends forever, since only such sends are guaranteed to work with remote objects.


 # E syntax
 def carRcvr := carMakerRcvr <- ("Mercedes")
 carRcvr <- moveTo(2,3)
 carRcvr <- moveTo(5,6)
 carRcvr <- moveTo(7,3)
 def fuelVow := carRcvr <- fuelRemaining()

Personal tools
more tools