From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3bf50ede73cff892 X-Google-Attributes: gid103376,public From: adam@irvine.com (Adam Beneschan) Subject: Re: Operators Questions Date: 1996/10/31 Message-ID: <559ad2$h9t@krusty.irvine.com>#1/1 X-Deja-AN: 193348849 references: <3275D478.5952@eurocontrol.fr> organization: /z/news/newsctl/organization newsgroups: comp.lang.ada Date: 1996-10-31T00:00:00+00:00 List-Id: 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