Do pure functions solve the "return const" problems?

Janice Caron caron800 at googlemail.com
Thu Apr 10 06:18:15 PDT 2008


On 10/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>  Why? Why wouldn't that merely be undefined behavior when you add pure?

Part of the contract for purity is that the result *MUST* be
independent of the order of evaluation of pure functions. As a general
rule, given

    h(f(),g())

The compiler is free to implement this as either

    temp1 = f();
    temp2 = g();
    h(temp1,temp2)

or as

    temp2 = g();
    temp1 = f();
    h(temp1,temp2)

or even as

    previouslyCachedValueFromLastTimeAround

That meas, if D's "pure" keyword is intended to give us functional
programming, then it's not going to let us have "out" parameters. The
way to return values is through the return statement.



More information about the Digitalmars-d mailing list