Re: Digest for EUforum at topica.com, issue 1880
- Posted by Christian.CUVIER at agriculture.gouv.fr Sep 17, 2002
- 354 views
Well, I thought I addressed this sore point of '=' polysemy. Here is what I have in mind: When a '=' is encountered, the character just preceding it is checked. May come from an idenifier ( [A-Za-z0-9_ ] ), is an arithmetic operator or is ')','>','<' or '!'. No confusion arises now in Euphoria with these settings. My suggestion is: add ':' to this list and set ":=" as a synonym for regular assignment. Since ordinary '=' has a clear meaning in conditions (while, if, elsif,...), don't disturb it, and let ":=" mean "=" when there may be an ambiguity. Since there must be one relational oprerator only in a condition, "a=b=c" would cause a syntax error. Both "a:=b=c" and "a=b:=c" would be unambiguously recognized. Since a statement cannot contain two level-0 assignments, a standalone "a:=b=c" would raise a syntax errror, just as "a=b=c" would. So, introducing ":=" as simultaneous assignment operator in a while, if or elsif statement would not break any existing code (since, right now, there is no legal ":=" compound) and would come closer to programmer's inner vision of the program. Allowing "a:=b" as standalone statement would not enhance clarity, since it would uselessly stand for "a=b". So it probably should be outlawed. Or did I miss anything? CChris > Date: Tue, 17 Sep 2002 11:59:37 +0000 > From: Andy Serpa <renegade at earthling.net> > Subject: RE: Andy and Pete, about := > > Christian.CUVIER at agriculture.gouv.fr wrote: > > > > > > > If a function has intentional side effects, so be it, and the > > programmer must realize it is executed each time it appears in code, > > whether to explicitly use the result or not. > > The point about that is we can't have the optimizer decide to compute a > function sometimes and not others if I'm counting on the side-effect -- > it must execute the exact number of times it actually appears. If it an > index lookup or something and it can optimize that, then fine. > > > hard to find bugs. > > Since ':' is not a legal character in identifiers, and a namespace > > must > > be followed by an identifier, inside which '=' is not legal either,... > > where would be the trouble incorporating this in existing code? > > > > > Well, if you're not to break any existing code, that means that your new > way of making an assignment would be added without changing the way '=' > currently works. As it stands, '=' can be used in expressions for > comparisons (in while statements, and on the right hand side of > assignments, i.e. expressions), and no assignments can occur in an > expression (like in a while statement -- for loops have a special > temporary assignment). So the meaning of '=' is determined by its > context. You propose that ':=' be allowed for assignments in a while > statement (which we can't do at all now). Does that also mean that we > can use it just for regular assignments (a := b) by itself on the line > and continue to use '=' that way as well? Or its ONLY allowed in a > loop? > > It seems if you're gonna do that, ':=' should be used for ALL > assignments, and '=' used for ALL comparisons. But it's "too late" for > that in Euphoria, I'm afraid. I'm not dead set against it, but it > doesn't exactly bring clarity... > >