The whole thing should look something like this:

So why should you care about these diagrams? Some people would rather work with pictures than with text. If they help you write a program, that's great! You can do anything in Scheme with diagrams.

However, one really good reason to think about programs in this way is that a diagram lets you see how a program works and when everything happens.

Let's see what happens when we type (dist 0 0 (+ 1 2) (* 2 2)), which should return 5.

Scheme will only try to call a procedure when it knows exactly what all of the inputs are.

There are two things that Scheme needs to know before it can call dist. Fortunately, it has everything it needs to know to figure out what (+ 1 2) and (* 2 2) are.

Which one of those two happens first? Who knows. All we know is that they both finish before dist ever starts.

Now we finally get to dist. All of the placeholders are replaced by their values.

There's plenty of work to do, but Scheme only has enough information to do two things at first. Again, we have no idea which one will happen first. It probably depends on which one has a better smile.

Again, there are only two things Scheme can do right now.

Now + has all of the information it needs.

And now we're done.

Discussion: Is it possible for one square to finish before the other - has even started?






Discussion: Is this possible? (y1 and y2 instead of 0 and 4)