pure or not pure?

Janice Caron caron800 at googlemail.com
Thu Apr 10 10:16:57 PDT 2008


On 10/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> Of course, but it is like a building block.  If I have a function that is
>  pure, and that function calls nothing but other pure functions AND 'new',
>  then why can't it also be proven to be pure?

It's not the calling of new that's a problem, it's the returning of
mutable data.

If we allow "pureish" functions, then maybe a "pureish" function could
return mutable data, but not a truly function.

The reason is that the compiler is allowed to cache the result (the
return value from any pure function), and to re-use that result,
instead of calling the function, whenever the input compares equal
with last time. If any of that data is mutable, it all goes haywire.

Seems to me that what's really needed here is a macro, because a macro
is basically just a function that's always inlined, so the function
body will be parsed /inside/ the pure specifier. Maybe macros could
solve that problem completely.



More information about the Digitalmars-d mailing list