[comp.lang.c] New assignment operator ->= ?

mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) (02/16/90)

It occurred to me some time ago that every binary operator in C (except the
logical ones - &&, ||)) except one have an analogous assignment operator:
  + has +=, - has -=, & has &=, etc.

Well, what about ->?  In tracing linked lists, I often do something like:
	p = head;
	while (*p->next)
	  p = p->next;
to get to the end, or something similar.  So why not
	p = head;
	while (*p->next)
	  p ->= next;

Anyone else agree?
 __
/\_\ Rob Mayoff
\/_/ mayoff@ccwf.cc.utexas.edu

woody@eos.UUCP (Wayne Wood) (02/16/90)

In article <24707@ut-emx.UUCP> mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) writes:
=It occurred to me some time ago that every binary operator in C (except the
=logical ones - &&, ||)) except one have an analogous assignment operator:
=                                          So why not
=	p = head;
=	while (*p->next)
=	  p ->= next;
=
=Anyone else agree?
= __

whadafuck???   i *LIKE* it!!!

/***   woody   ****************************************************************
*** ...tongue tied and twisted, just an earth bound misfit, I...            ***
*** -- David Gilmour, Pink Floyd                                            ***
****** woody@eos.arc.nasa.gov *** my opinions, like my mind, are my own ******/

amoss@batata.huji.ac.il (amos shapira) (02/17/90)

mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) writes:

>Well, what about ->?  In tracing linked lists, I often do something like:
> p = head;
> while (*p->next)
>   p = p->next;
>to get to the end, or something similar.  So why not
> p = head;
> while (*p->next)
>   p ->= next;

Well, I though just about such an operator and from the same reasons. But, as
far as I understand compilers, using such an operator will not gain much code
savings, if at all.

On the other hand it MIGHT be more readable in several places (especially
when updating a pointer who's address is given inside another structure
(like a->b->c ->= next;) but then, how meny times do you write such a code?

>Anyone else agree?

I think I will use this operator here and there if it will become a standard.

> __
>/\_\ Rob Mayoff
>\/_/ mayoff@ccwf.cc.utexas.edu

- Amos Shapira

amoss@batata.bitnet
amoss@batata.huji.ac.il

wietse@wzv.win.tue.nl (Wietse Z. Venema) (02/17/90)

mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) writes:

>So why not
>	while (*p->next)
>	  p ->= next;

Don't forget the .= operator. Unfortunately, such language features would 
prohibit other language perversions such as:

		a ^+= b <-> a ^= a += b <-> a = a ^ a + b
		p ->= q <-> p -= p >= q <-> p = p - p > q

(:-))

mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) (02/21/90)

In an article entitled New assignment operator ->= ?, wietse@wzv.win.tue.nl (Wietse Z. Venema) enlightens us with:

>Don't forget the .= operator. Unfortunately, such language features would 
>prohibit other language perversions such as:
>
>		a ^+= b <-> a ^= a += b <-> a = a ^ a + b
>		p ->= q <-> p -= p >= q <-> p = p - p > q
>
While I am sure you at least partially joking, it seems that you dislike my
suggestion.  Let me respond:

  The .= operator would probably never be used.  I don't think a structure can
be a member of itself, and I don't think a union can be a member of itself, so
you can't assign a structure variable to a member of itself.  On the other
hand, a pointer to a structure can be a member of that same structure, and
assigning that member of the structure to a variable pointing to that structure
is a logical, I might even say common, operation.  While it would not cause the
compiler to generate less instructions, as += might (at least in
non-optimizing compilers), it is shorter to type and no less readable (at
least, no less readable than a+=b, etc).

Furthermore, the += operator, and its siblings give the idea of "incrementing"
the variable, or scaling it, etc.  To me, incrementing a numerical variable
seems analogous to advancing a pointer to a linked list along that list.

So far, I've gotten five positive responses.  I also got one response that
pointed out that -> is not exactly a binary operation, since the right-hand
identifier indicates a structure element, not a variable. And, of course,
the response I am replying to.

Anyone else have an opinion on this?

Also, can anyone (and I'm sure someone can) tell me how to contact the ANSI
C committee?
 __
/\_\ Rob Mayoff
\/_/ mayoff@ccwf.cc.utexas.edu

wswietse@tuewse.lso.win.tue.nl (Wietse Venema) (02/21/90)

wietse@wzv.win.tue.nl (Wietse Z. Venema):

    Unfortunately, such language features would 
    prohibit other language perversions such as:

	a ^+= b <-> a ^= a += b <-> a = a ^ a + b
	p ->= q <-> p -= p >= q <-> p = p - p > q

mayoff@walt.cc.utexas.edu (Rob "The" Mayoff):

    While I am sure you at least partially joking, it seems that you
    dislike my suggestion.

No fundamental objections from my side; my remark was intended as a
reminder that one should be careful in proposing a language extension.
New features may prohibit the implementation of other ones. The ^+=
example was NOT intended as an example of a useful language extension.

maart@cs.vu.nl (Maarten Litmaath) (02/22/90)

In article <24810@ut-emx.UUCP>,
	mayoff@walt.cc.utexas.edu (Rob "The" Mayoff) writes:
)...
)Furthermore, the += operator, and its siblings give the idea of "incrementing"
)the variable, or scaling it, etc.  To me, incrementing a numerical variable
)seems analogous to advancing a pointer to a linked list along that list.
)...

Indeed.  Despite `->' not being a `true' binary operator, I consider the
absence of a `->=' operator one of C's oversights.
--
  "Ever since the discovery of domain addresses in the French cave paintings
  [...]"  (Richard Sexton)      |  maart@cs.vu.nl,  uunet!mcsun!botter!maart

jeffa@hpmwtd.HP.COM (Jeff Aguilera) (02/22/90)

> Also, can anyone (and I'm sure someone can) tell me how to contact the ANSI
> C committee?

Do you really think that they would listen?  
-----
jeffa

henry@utzoo.uucp (Henry Spencer) (02/24/90)

In article <680019@hpmwjaa.HP.COM> jeffa@hpmwtd.HP.COM (Jeff Aguilera) writes:
>> Also, can anyone (and I'm sure someone can) tell me how to contact the ANSI
>> C committee?
>
>Do you really think that they would listen?  

They would listen, but their response would probably be:

	(a) Come back in five years when ANSI C is due for revision.

	(b) You will get a much more favorable hearing then if you have
	implemented this feature and used it; there is no substitute for
	real experience when deciding whether a feature is practical and
	useful.  Almost everything actually adopted for ANSI C had been
	tried in a compiler first.

	(c) The need seems slight; you're going to have to make a very
	good case for it to justify changing an existing language.
-- 
"The N in NFS stands for Not, |     Henry Spencer at U of Toronto Zoology
or Need, or perhaps Nightmare"| uunet!attcan!utzoo!henry henry@zoo.toronto.edu