Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Manu turkeyman at gmail.com
Tue Nov 3 07:05:19 UTC 2020

On Tue, Nov 3, 2020 at 1:15 PM Q. Schroll via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Tuesday, 3 November 2020 at 02:30:58 UTC, Manu wrote:
> > Perhaps my implementation implies additional grammar changes
> > that I didn't notice.
> It does, if it should work on types. In the easiest case, if you
> want
>      alias X(Args...) = (T!Args)...;
> to work like
>      alias X(Args...) = staticMap!(T, Args);
> you cannot do that by merely adding a new PostfixExpression. It
> is necessary to add `...` to BasicType2X, i.e.
>      BasicType2X:
>          *
>          [ ]
>          [ AssignExpression ]
>          [ AssignExpression .. AssignExpression ]
> +       ...
>          [ Type ]
> but I may have overlooked something and it might not suffice. The
> grammar concerning "type expressions" is convoluted and has some
> stuff going on in AltDeclarator where I'm not entirely sure it
> can be ignored.

You're right, and a change like that does exist in my implementation
somewhere; I just need to look again at the implementation to spot it and
confirm it in the grammar changes.
I wondered if I overlooked some cases too; but the unit tests are fairly
comprehensive and exercise all the constructs that we ever imagined could
be useful.

There's a grammar change that supports:
   alias staticMap(F, Args...) = F!Args...;
And also:
  MyTemplate!(expr...) <-- appearance in template parameter lists

It's also deliberate and necessary that the grammar is NOT modified such
that `...` could be accepted in argument list definitions, because that's
where ambiguity can occur.
If you want to use `...` in an argument list, you can make an alias on the
preceding line:
  alias MappedArgs = TupExpr...;
  void fun(MappedArgs args) { ... }  <-- `...` can not appear in a
parameter list, so hoist it to the line above

I actually really like this incidental restriction; it makes declarations
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20201103/57da0b02/attachment.htm>

More information about the Digitalmars-d mailing list