Re: Implementing an "in" operator

"Charles Bryant" <>
20 Nov 2002 15:19:24 -0500

          From comp.compilers

Related articles
Implementing an "in" operator (Ed Davis) (2002-11-13)
Re: Implementing an "in" operator (Charles Bryant) (2002-11-20)
Re: Implementing an "in" operator (Steve Siegfried) (2002-11-24)
Re: Implementing an "in" operator (Ed Davis) (2002-11-26)
| List of all articles for this month |

From: "Charles Bryant" <>
Newsgroups: comp.compilers
Date: 20 Nov 2002 15:19:24 -0500
Organization: Compilers Central
References: 02-11-079
Keywords: design
Posted-Date: 20 Nov 2002 15:19:24 EST

Ed Davis <> wrote:
>Any ideas on how one would implement an "in" operator?
>As in (no pun intended):
> if (a in b,c,d..e)
> statements;
>translates to:
> if (a == b or a == c or (a >= d and a <=e))
> statements;

I'd be inclined to make 'b,c,d..e' be a literal of some appripriate
type and make 'in' a binary operator taking an object of type T as its
left operand and an object of type 'list of T', 'set of T' or suchlike
as it right operanad. This would also allow constructs like:

x = <nasty complex range specification>
if (a in x) {
} else if (b in x) {

making it a lot clearer that the same list of ranges is used twice.

Post a followup to this message

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