Function as Tank

Programming Language

imperative or functional / any

Form

Analogy

Attribution — Origin / Source

Collected by Matthias Hauswirth — Book, Brian Harvey

Conceptual Advantage

Makes explicit that functions have inputs (parameters) and outputs (return value).

Mapping

PLNM
function tank
parameters hoppers on top of tank
return value output pipe on bottom of tank

Draws Attention To

Parameter passing and return value.

Use When

First introducing functions.

Cost

not captured

Details

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:

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.

Comments or Feedback?

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".

Create an Issue on GitHub