Re: Overloaded logic operators

"Bartc" <bc@freeuk.com>
Tue, 25 Nov 2008 23:08:08 GMT

          From comp.compilers

Related articles
[5 earlier articles]
Re: Overloaded logic operators mike@mike-austin.com (Mike Austin) (2008-11-25)
Re: Overloaded logic operators mike@mike-austin.com (Mike Austin) (2008-11-25)
Re: Overloaded logic operators mike@mike-austin.com (Mike Austin) (2008-11-25)
Re: Overloaded logic operators lkrupp@pssw.com (Louis Krupp) (2008-11-25)
Re: Overloaded logic operators mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-11-25)
Re: Overloaded logic operators m.helvensteijn@gmail.com (2008-11-25)
Re: Overloaded logic operators bc@freeuk.com (Bartc) (2008-11-25)
Re: Overloaded logic operators cdodd@acm.org (Chris Dodd) (2008-11-25)
Re: Overloaded logic operators torbenm@pc-003.diku.dk (2008-11-26)
Re: Overloaded logic operators fswarbrick@gmail.com (Frank Swarbrick) (2008-11-27)
Re: Overloaded logic operators dot@dotat.at (Tony Finch) (2008-12-01)
Re: Overloaded logic operators alexc@TheWorld.com (Alex Colvin) (2008-12-03)
Re: Overloaded logic operators haberg_20080406@math.su.se (Hans Aberg) (2008-12-04)
| List of all articles for this month |

From: "Bartc" <bc@freeuk.com>
Newsgroups: comp.compilers
Date: Tue, 25 Nov 2008 23:08:08 GMT
Organization: Compilers Central
References: 08-11-110 08-11-116 08-11-125
Keywords: syntax, design
Posted-Date: 27 Nov 2008 11:58:53 EST

m.helvensteijn@gmail.com> wrote
>> (Being able to write if a<b<c is neat though and I've just added
>> that to my language, with about 5 lines of code; it just converts to
>> if (a<b) and (b<c).)
>
> Yes, chained comparison is neat. But watch out. If someone wrote: (a <
> b() < c), he would expect b() to only be evaluated once, not twice.
> This makes a big difference if b() has side-effects. Also, the syntax
> can be extended to mixed comparison operators. For example: (a < b = c
> < d).
>
> Did you catch all that in 5 lines of code? Then I admire your code
> modularity. :-)


No; someone mentioned about evaluating b twice, and I fixed it for when b is
an assignment:


a < (b:=x) < c


becomes: 'a < (b:=x) and b < c'. It just means that the user has to create
an explicit copy by writing (b:=x) instead of just x, when x has side
effects.


That took another 5 or 6 lines. This is all just syntax after all.


And yes the original 5 lines did deal with all six relational operators, and
could cope (by an accident of recursion) with long chains such as a<b<c<d<e.


--
Bartc


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.