On Tuesday, 3 October 2023 at 10:39:19 UTC, matheus wrote:

Nice article but I think that I found a bug:

    g(f(e(d(c(b(a))),3)));

    a.b.c.d(3).e.f.g;

"That’s the equivalent, but execution flows clearly left-to-right. Is this an extreme example, or the norm?"

Well I don't think they're equivalent:

    g(f(e(d(c(b(a))),3)));

I the first example "e" is receiving two arguments. While in the latter "d" is being receiving whatever "c" returns and "3".

Matheus.

Agreed. Even though I do like UFCS, I find the above confusing to follow despite being more pleasing to the eye. I had to break it down and, as Matheus already pointed out, looked incorrect.

This appears to be the correct code.

```d
int a() { return 1;  }
int b(int i) { return i+1; }
int c(int i) { return i+2; }
int d(int i) { return i+3; }
int e(int a, int b) { return a+b; }
int f(int i) { return i+4; }
int g(int i) { return i+5; }

void main()
{
    import std.stdio : writeln;
    auto r = g(f(e(d(c(b(a))),3)));
    auto r2 = a.b.c.d.e(3).f.g;

    writeln(r);    // 19
    writeln(r2);   // 19
}
```
  • From the D Bl... Mike Parker via Digitalmars-d-announce
    • Re: From... zjh via Digitalmars-d-announce
      • Re: ... zjh via Digitalmars-d-announce
    • Re: From... Max Samukha via Digitalmars-d-announce
      • Re: ... rassoc via Digitalmars-d-announce
      • Re: ... Walter Bright via Digitalmars-d-announce
        • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-announce
        • ... Max Samukha via Digitalmars-d-announce
          • ... Walter Bright via Digitalmars-d-announce
    • Re: From... matheus via Digitalmars-d-announce
      • Re: ... Martyn via Digitalmars-d-announce
        • ... bachmeier via Digitalmars-d-announce
      • Re: ... Dom DiSc via Digitalmars-d-announce
        • ... matheus via Digitalmars-d-announce
          • ... Walter Bright via Digitalmars-d-announce
    • Re: From... user1234 via Digitalmars-d-announce
      • Re: ... matheus via Digitalmars-d-announce
      • Re: ... Mike Parker via Digitalmars-d-announce
    • Re: From... Walter Bright via Digitalmars-d-announce
    • Re: From... claptrap via Digitalmars-d-announce
      • Re: ... bachmeier via Digitalmars-d-announce

Reply via email to