(future exp) allows the programmer to say to the evaluator: I will need the value of exp some time in the future. This means the evaluator has more freedom in choosing when to evaluate exp. Some possibilities:
- Evaluate exp directly: this gives the future construct the semantics of the identity function.
- Evaluate exp when its value is needed: the future becomes a delay.
- The evaluation can start between 1 and 2, and in the best-case scenario the value is available when needed.
(future exp) creates a future value that can be resolved by its cousin procedure touch. touch always returns the value of exp, but it is possible it has to wait for it to become available, so it is a blocking operation.
Futures are first class values and can freely be passed around. So when is it necessary to use touch? At least before the value of exp is needed. And who has to perform the touch? Again some options:
- The programmer manually introduces touch where necessary.
- The evaluator, when needing a strict value, checks for futures and touches if necessary.
- The evaluator does value-flow analysis and introduces the necessary touch operations.
Options 2 and 3 makes the use of futures more transparent for the programmer, since he or she doesn't have to deal with touch explicitly. But wait... let's extend this principle. What if the evaluator can perform an analysis to decide where to introduce futures? That way, not only touch but also future becomes transparent, resulting in automatic parallelization.
The analysis needed for safe introduction of futures is dependency analysis. As said before, introducing futures can change the semantics of a program. The only way to make sure this doesn't happen is to check for interdependence between expressions. In short, if two expressions have no dependencies, evaluating them in parallel cannot change the meaning of a program.
So, to conclude, future and touch available at the source level in Streme only to manually test out concurrency in Streme. Ideally, in the near "future", the programmer should not worry about future/touch at all, since the evaluator will take care of it. Hopefully.