Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

x < y < z using user-defined types and overloading

1 view
Skip to first unread message

Gordon V. Cormack

unread,
Oct 17, 1986, 2:04:02 PM10/17/86
to
There has been discussion in the net on languages that allow the
notation x < y < z
as a shorthand for x < y and y < z

With user-defined types and overloaded operators (like in Ada)
this is easy to set up (I will spare you the tedious Ada Syntax).

type tempresult = record
val: real
tst: bool
end

operator "<" (a: real, b: real) bool = ... the normal comparison

operator "<" (a: real, b: real) tempresult =
(val => b, tst => a < b)

operator "<" (a: tempresult, b: real) bool =
(a.tst and a.val < b)

operator "<" (a: tempresult, b: real) tempresult =
(val => b, tst => a.tst and a.val < b)

Aren't data types wonderful?
--
Gordon V. Cormack CS Department, University of Waterloo
gvco...@watdaisy.uucp gvcormack%watd...@waterloo.csnet

Brad Templeton

unread,
Oct 17, 1986, 8:20:37 PM10/17/86
to
In article <79...@watdaisy.UUCP> gvco...@watdaisy.UUCP (Gordon V. Cormack) writes:
>There has been discussion in the net on languages that allow the
>notation x < y < z
>as a shorthand for x < y and y < z
>
>With user-defined types and overloaded operators (like in Ada)
>this is easy to set up (I will spare you the tedious Ada Syntax).
>
>Aren't data types wonderful?
>--
>Gordon V. Cormack CS Department, University of Waterloo

Sure, but I have been wondering what all the fuss is. x < y < z
is not all that exciting, and not much shorter than what it is
supposed to shorten. Certainly I don't see compilers generating
better code from it.

There are lots of valuable things you can do with more general
languages, but I don't think this is one of them. I can't imagine
a language designer deliberately complicating things just to support
this one.


--
Brad Templeton, Looking Glass Software Ltd. - Waterloo, Ontario 519/884-7473

ga...@batcomputer.uucp

unread,
Oct 23, 1986, 7:38:18 PM10/23/86
to
In a recent article br...@looking.UUCP (Brad Templeton) wrote:
>Sure, but I have been wondering what all the fuss is. x < y < z
>is not all that exciting, and not much shorter than what it is
>supposed to shorten. Certainly I don't see compilers generating
>better code from it.
>

Think back many many years ago to CS 101 and the first time you had
to test whether a number was between two other numbers: how did you
instantly and naturally write it down ? And what did the compiler
say?


>There are lots of valuable things you can do with more general
>languages, but I don't think this is one of them. I can't imagine
>a language designer deliberately complicating things just to support
>this one.
>

"Valuable" includes "more understandable", not just "more powerful" :-)

garry wiegand (garry%cadi...@cu-arpa.cs.cornell.edu)

0 new messages