Definitions & assignations

In Arplan, there are ways to "connect" symbols (aka identifiers) to values/expressions. These are:

  • =
  • :=
  • ::=

They have all three very distinct meanings and will be explained in the reverse order.

 

The ::=

 

This is called instant assignation. Example:

 

a ::= f(x)

 

The meaning: "compute f(x) and when you have the result put it in a"

 

It is the classical assignation like the one used in most mainstream programming languages.

 

 

The :=

 

This symbol is called delayed assignation. It is an assignation, like in the previous case, but with a twist:

 

a := f(x)

 

Meaning: "start computing f(x) and when you have finished the result put it in a ...meanwhile I will continue the program"

 

This is useful to execute tasks in parallel. These could be computations, remote calls or anything else that takes some time.

 

Let us do an example where three requests are sent to remote servers. The reply is an integer and, for simplicity, we assume it always arrives ... but it may take a bit time.

 

x := server1 : remote-request ()

y := server2 : remote-request ()

z := server3 : remote-request ()

 

print "requests sent"

print  max([x, y, z])

 

In this example, the three requests will be sent (quasi) at the same time. Thus, the "requests sent" will be immediately printed. On the opposite, the "max([x, y, z])" will take some time before being printed. In order for max to be evaluated, the computation of the 3 variables x, y, z must be finished (the response arrived in this case).

 

When using the ':=', it processes the computation in a separate thread. And when further calls need "currently computed" variables, they will simply wait for them to finish. This can therefore lead to versatile dataflows as is illustrated by the following example.

 

a := something-that-takes-long

b := do-something-with (a)

 

x := something-else-that-takes-long

y := do-something-with (x)

z := do-something-with (y)

 

print (b, z)

 

Instead of being computed one after another, there will be two "pathes of execution":

  • a -> b
  • x -> y -> z

These two sets of values will be computed independently without interferring with each other.

 

 

The =

 

This is called a definition.  Example:

 

x = a + b

 

Meaning: "x is always equal to a + b"

 

It is an equality in the mathematical sense. It is defined once and for all and is "atemporal". The symbol 'x' could be replaced everywhere by 'a + b' without affecting the program. Indeed, 'x' is always equal to the sum of a and b ...even if a and b change with time!

 

What follows is a short example showing that printing x at different times may result in different values.

 

x = a + b

 

do

a := 2

b := 3

 

print x     # 5

 

a := 4

b := 5

 

print x      # 9

 

Of course, it has no sense to define a symbol multiple times and is therefore forbidden.

 

x = a

x = b    # error : 'x' already defined as 'a'

 

Such strong equalities have two big consequences:

  • It does not matter in what order you place these definitions
  • It does not matter in what order they are evaluated

Indeed, in any case, the result is the same since they are pure equalities.

 

 

 

 

 

 

 



Deleted content


In words, it could be translated as follows:

  1. make the remote request to server 1 and put it in x when the result is obtained
  2. make the remote request to server 2 and put it in y when the result is obtained
  3. make the remote request to server 3 and put it in z when the result is obtained
  4. print "requests sent"
  5. print the max of x, y and z. ...and in order to do this wait until the 3 are evaluated.


As a side comment, if one wanted to have the requests be performed one after another sequencially instead of in parallel, it is sufficient to use '::=' instead of ':='.