LWN.net Logo

Syntax flubs

Syntax flubs

Posted Jan 29, 2010 9:07 UTC (Fri) by dgm (subscriber, #49227)
In reply to: Syntax flubs by alextingle
Parent article: GCC to merge Go support

>Because things like this make your head hurt...
>*a.b->c.d->e *= *p->q.r * *x[2];

Maybe the case for prefix operators is much more simple:

*a=b; /* ok */
a*=b; /* what should we do with this? */


(Log in to post comments)

Syntax flubs

Posted Jan 29, 2010 18:25 UTC (Fri) by tjc (subscriber, #137) [Link]

Yeah, that's a problem.

The issue isn't that postfix indirection is better than prefix; the real issue is that postfix declaration is better than prefix because then the pointer declarator is on the same precedence level as () and [], and complex declaration are less... complex. This is problematic in a language like C where declaration mimics use, since the best syntax for declaration is not the same as the best syntax for use.

Syntax flubs

Posted Jan 30, 2010 10:52 UTC (Sat) by ncm (subscriber, #165) [Link]

No, it is no problem. Of course Go is not bound to match C's operators in any
case, but if they chose to be so bound, they could use "@" for the purpose. As
could, indeed, C or C++. I.e., those languages could also fix the problem, even at
this late date. They can be excused for not doing so, but Go cannot.

Syntax flubs

Posted Feb 4, 2010 18:25 UTC (Thu) by tjc (subscriber, #137) [Link]

I agree, using '@' as an indirection operator would work. But it looks funny, especially as a postfix operator. I would probably get used to it.

I better like the idea of separating declaration syntax from expression syntax and using '*' as a postfix pointer declarator and '[]' as an infix[1] indirection operator, like this:

var p *[10]int;
var a [10]*int;

[p][0] = 1;
[a[0]] = 1;

I guess I could call this "square lisp" syntax. :)

[1] This really isn't infix, since the operand is infix, not the operator, but I don't know the correct term for this form.

Syntax flubs

Posted Feb 4, 2010 22:51 UTC (Thu) by anselm (subscriber, #2796) [Link]

[1] This really isn't infix, since the operand is infix, not the operator, but I don't know the correct term for this form.

Outfix?

Syntax flubs

Posted Feb 7, 2010 1:44 UTC (Sun) by tjc (subscriber, #137) [Link]

Outfix?
You are indeed correct!

http://www.abstractmath.org/MM/MMFunctionValue.htm#_Toc223234910

It seems obvious in retrospect. Thanks.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds