UFCS syntax I never saw before.

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue May 22 14:33:20 UTC 2018


On Tuesday, May 22, 2018 13:48:16 aliak via Digitalmars-d-learn wrote:
> On Monday, 21 May 2018 at 18:53:19 UTC, Jonathan M Davis wrote:
> > writeln = "foo";
> >
> > is legal, and it's dumb, but it hasn't mattered much in
> > practice. So, causing a bunch of code breakage in order to
> > disallow it is unlikely to go over well. It would also then
> > make getters and setters inconsistent in that setters would
> > require @property and getters wouldn't. How much that matters
> > is debatable, but it does make such a change less palatable.
> >
> > [...]
>
> Can't assignment to a function be fixed though? Are there any
> cases where fixing that will cause problems for @property free
> functions because they all must take more that one parameter i
> assume.
>
> It's quite a big wart so we don't have to fix all of @property at
> least, but that should be fixed if fixing it does not crap on
> UFCS and @property free functions.

A free function with a single argument works just fine as a setter property.
e.g. you could do something like

void env(Tuple!(string, string)[] str)
{
    // set environment variables
}

env = [tuple("foo", "bar")];

is perfectly legal. I question that there are many cases where such a
function would be considered good design, but basically any case where it
would make sense to have a function act like a global variable is currently
allowed but would be disallowed if you couldn't have a setter property with
only one argument.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list