Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
18 Introduction to Programming Concepts The multiplication X*X waits until X is bound. The first Browse immediately displays start . The second Browse waits for the multiplication, so it displays nothing yet. The {Delay 10000} call pauses for 10000 milliseconds (i.e., 10 seconds). X is bound only after the delay continues. When X is bound, then the multiplication continues and the second browse displays 9801. The two operations X=99 and X*X can be done in any order with any kind of delay; dataflow execution will always give the same result. The only effect a delay can have is to slow things down. For example: declare X in thread {Browse start} {Browse X*X} end {Delay 10000} X=99 This behaves exactly as before: the browser displays 9801 after 10 seconds. This illustrates two nice properties of dataflow. First, calculations work correctly independent of how they are partitioned between threads. Second, calculations are patient: they do not signal errors, but simply wait. Adding threads and delays to a program can radically change a program’s appearance. But as long as the same operations are invoked with the same argu- ments, it does not change the program’s results at all. This is the key property of dataflow concurrency. This is why dataflow concurrency gives most of the advantages of concurrency without the complexities that are usually associated with it. 1.12 State How can we let a function learn from its past? That is, we would like the function to have some kind of internal memory, which helps it do its job. Memory is needed for functions that can change their behavior and learn from their past. This kind of memory is called explicit state . Just like for concurrency, explicit state models an essential aspect of how the real world works. We would like to be able to do this in the system as well. Later in the book we will see deeper reasons for having explicit state. For now, let us just see how it works. For example, we would like to see how often the FastPascal function is used. Istheresomeway FastPascal can remember how many times it was called? We can do this by adding explicit state. A memory cell There are lots of ways to define explicit state. The simplest way is to define a single memory cell . This is a kind of box in which you can put any content. Many programming languages call this a “variable”. We call it a “cell” to avoid confusion with the variables we used before, which are more like mathemati- cal variables, i.e., just short-cuts for values. There are three functions on cells: NewCell creates a new cell, := (assignment) puts a new value in a cell, and @ Copyright c ± 2001-3 by P. Van Roy and S. Haridi. All rights reserved.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1.13 Objects 19 (access) gets the current value stored in the cell. Access and assignment are also called read and write. For example: declare C={NewCell 0} C:[email protected]+1 {Browse @C} This creates a cell C with initial content 0, adds one to the content, and then displays it.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/10/2011.

Page1 / 30


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online