On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote:
On Thursday, 16 June 2022 at 23:59:06 UTC, Antonio wrote:
Is it there any way to apply UFCS on the returned method in the same expression?

Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for functions that have a name, not anonymous functions.

Lets tray with a name :-)

```d
auto doSomething(string text)
{
  return (string text2)
  {
    import std.stdio;
    writeln(text,",",text2);
  };
}

void main()
{
  auto doHello = doSomething("Hello");
  doHello("X");
  "X".doHello();
}
```

Error: onlineapp.d(16): Error: no property `doHello` for type `string`

It's true... the favomous "Rationale: Local function symbols are not considered by UFCS to avoid unexpected name conflicts." (I consider it absurd... but I'n no-one)

Well lets try another possibility taking in account the power of CTFE

```d
auto doSomething(string text)
{
  return (string text2)
  {
    import std.stdio;
    writeln(text,",",text2);
  };
}

auto doHello = doSomething("Hello");

void main()
{
  doHello("X");
  "X".doHello();
}

```

Error: onlineapp.d(3): Error: closures are not yet supported in CTFE

:-/

UFCS vs Functional curring... nice battle :-)





Reply via email to