PreviousUpNext

12.13  Function definitions

“I notice that you use plain, simple language,
  short words and brief sentences. That is the
  way to write English — it is the modern way
  and the best way. Stick to it; don’t let fluff
  and flowers and verbosity creep in.

“When you catch an adjective, kill it.
  No, I don’t mean utterly, but kill most
  of them — then the rest will be valuable.
  They weaken when they are close together.
  They give strength when they are wide apart.

“An adjective habit, or a wordy, diffuse,
  flowery habit, once fastened upon a person,
  is as hard to get rid of as any other vice.”

                                                —
Mark Twain

Default format is:

    fun foo arguments
        =
        body;

In the typical case where the body contains more than one statement, this becomes

    fun foo arguments
        =
        {   statement;
            statement;
        }

With a long argument list this becomes one of

    fun foo
            argument
            argument
            argument
            ...
        =
        {   statement;
            statement;
        }

    fun bar
        (
            argument
            argument
            argument
            ...
        )
        =
        {   statement;
            statement;
        }

Use a where clause to improve readability when the function body consists of some definitions combined in the result:

    fun foo arguments
        =
        bar zot
        where
            bar = expression;
            zot = expression;
        end;

Use one-line function definitions only to expose parallelism:

    fun foo = tum diddle dum;
    fun bar = tum diddle dee;

Pattern-matching function definitions are implicit case statements. Lay them out accordingly:

    fun foo arguments => expression;
        foo arguments => expression;
        foo arguments => expression;
        ...
    end;

    fun foo arguments
            =>
            {    statement;
                 statement;
                 statement;
                 ...
            };

        foo arguments
            =>
            {    statement;
                 statement;
                 statement;
                 ...
            };

        foo arguments
            =>
            {    statement;
                 statement;
                 statement;
                 ...
            };
    end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext