Next / Previous / Shipman's Home Sweet Homepage / Site map

Cleanroom intended functions: Compound I/Fs

Often, procedures have different semantics depending on different values of their parameters. For such cases, we use this structure:

    # [ if condition-1 ->
    #     intended-function-1
    #   else if condition-2 ->
    #     intended-function-2
    #   else if ...
    #     ...
    #   else ->
    #     intended-function-n ]

This means that if condition-1 is satisfied, the procedure has I/F intended-function-1, and so on; if none of the conditions are satisfied, the procedure has I/F intended-function-n.

Here's an example:

    # [ if a < b ->
    #     return a
    #   else ->
    #     return a + b ]
    if  a < b:
        return a
    else:
        return a + b

The notation I is used to mean ``identity,'' that is, do nothing, in compound I/Fs. For example:

    # [ if a = 0 ->
    #     raise ValueError
    #   else ->
    #     I ]
This means: if a is zero, raise a ValueError exception, else do nothing.
Next: Cleanroom intended functions: Preconditions
See also: Writing Cleanroom intended functions
Previous: Cleanroom intended functions: Special I/Fs
Site map
John W. Shipman, john@nmt.edu
Last updated: 2002/09/28 01:33:31
URL: http://www.nmt.edu/~shipman/soft/clean/compound-i-f.html