[Issue 5749] argument evaluation order of chained function from right

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 18 13:21:11 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5749


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-03-18 13:17:57 PDT ---
That's true for arguments to a single function.  But what about arguments to
different functions in the same expression?  Considering that you MUST call the
functions in left-to-right order given because the next function in the chain
depends on the result of the previous.

I'm not saying the current behavior is wrong or not expected, but it feels
weird when one parameter is evaluated left to right (the struct reference) and
the other parameter is evaluated right to left *across the expression*.

For example, if I do:

a(1)(2);

it prints
i=1
i=2

I would expect what Fawzi did.  It would be nice to get an explanation of why
it works this way, if it is intentional.

What would you expect for this:

size_t inc(ref size_t i) { return ++i; }

a(inc(i))(inc(i));

would you expect it to first run both incs, caching the return values and then
using that to call a?  Because that's what it does.

Also, this is weird too:

struct A
{
  A opCall(ref size_t i)
  {
    printf("i=%d\n", i);
  }
}

a(++i)(++i);

prints:

i=2
i=2

If I change i to a large struct, then the prospect of pushing multiple copies
of that large struct on the stack so I can cache the results becomes alarming.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list