comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: Re: Operators Questions
Date: 1996/10/31
Date: 1996-10-31T00:00:00+00:00	[thread overview]
Message-ID: <559ad2$h9t@krusty.irvine.com> (raw)
In-Reply-To: mheaney-ya023180003010961903550001@news.ni.net


mheaney@ni.net (Matthew Heaney) writes:
 
 >Language designers: any reason overloading of "in" is too difficult for
 >inclusion in the language?  Why can't you do this already?  This exclusion
 >of the ability to overload "in" seems rather odd and unexpected.

It's not really odd, since overloading pertains to operators, and "in"
isn't an operator.  The overloadable operators all take one or two
expressions as arguments (loosely speaking); "in" takes an expression
on the left and a range or type mark on the right.

This doesn't mean "in" couldn't be overloaded, if this feature were
really desired in the language; but making the compiler handle this
wouldn't be as simple as adding "in" to its list of overloadable
operators.  Suppose the compiler sees

    A in B

where A and B are variables; it would have to look ahead and see if
the next lexeme is ".." to determine whether "in" is being used as a
membership test or as an overloadable operator with A and B as
arguments.  I'd bet that most compilers would need extra code to
handle this case, unless perhaps they're already treating ".." like an
operator internally.  Even worse: Would "in" have a higher or lower
precedence than, say, "+"?  If higher, the compiler would have a nasty
time dealing with both

    A in B + C                which means (A in B) + C

and 

    A in B + C .. D + E       which means A in (B+C)..(D+E)

How far ahead does the compiler have to look to determine what
operator applies to what arguments? 

In any case, it appears that the benefit would not be worth the cost.

                                -- Adam




  reply	other threads:[~1996-10-31  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-29  0:00 Operators Questions Richard Irvine
1996-10-29  0:00 ` Norman H. Cohen
1996-11-07  0:00   ` William Frye
1996-10-29  0:00 ` Robert Dewar
1996-10-30  0:00 ` Fergus Henderson
1996-10-30  0:00 ` Matthew Heaney
1996-10-31  0:00   ` Adam Beneschan [this message]
1996-10-31  0:00   ` Michael F Brenner
1996-10-31  0:00 ` Jon S Anthony
1996-10-31  0:00   ` Adam Beneschan
1996-11-02  0:00   ` Robert Dewar
1996-11-02  0:00 ` Jon S Anthony
1996-11-05  0:00 ` Jon S Anthony
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox