imperative or functional / any
Analogy
Collected by Matthias Hauswirth — Book, Brian Harvey
Makes explicit that functions have inputs (parameters) and outputs (return value).
PL | NM |
---|---|
function | tank |
parameters | hoppers on top of tank |
return value | output pipe on bottom of tank |
Parameter passing and return value.
First introducing functions.
Brian Harvey also calls this notional machine “Plumbing Diagram”. He uses it in his book, Computer Science Logo Style: Symbolic Computing (Chapter 2, Procedures, PDF).
The following example shows LOGO code and the corresponding plumbing diagram:
print word sum 2 4 "es
The book introduces the diagram as follows:
Using the output from one procedure as an input to another procedure is called composition of functions. Some people find it helpful to look at a pictorial form of this analysis. We can represent each procedure as a kind of tank, with input hoppers on top and perhaps an output pipe at the bottom. (This organization makes sense because gravity will pull the information downward.) … We can put these parts together to form a kind of “plumbing diagram” of the instruction. … In that diagram the output pipes from one procedure are connected to the input hoppers of another. Every pipe must be connected to something. The inputs that are explicitly given as numbers in the instruction are shown with arrows pointing into the hoppers.
You can annotate the diagram by indicating the actual information that flows through each pipe.
Do you have feedback on this notional machine? Did you find a mistake, or do you have a request for improvement? You can create an Issue on GitHub, where the description is hosted. This way we can see your feedback and address it.
For this, you need a GitHub account. Then follow this link to see the source file of this page. In there, click the ... left of the highlighted line, then pick "Reference in a new issue".