Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!ames!sdcsvax!ucbvax!santra.UUCP!news From: news@santra.UUCP (news) Newsgroups: comp.lang.modula2 Subject: Re: Number of elements in a set Message-ID: <8709192023.AA27593@jade.berkeley.edu> Date: Thu, 17-Sep-87 17:59:43 EDT Article-I.D.: jade.8709192023.AA27593 Posted: Thu Sep 17 17:59:43 1987 Date-Received: Sun, 20-Sep-87 16:03:18 EDT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Info-Modula2 Distribution List Organization: The ARPA Internet Lines: 47 >It >is not hard to implement sets of effectively unbounded size; further, it is >usually more efficient, and certainly more readable and useful to have large >sets than to simulate this with the corresponding user code. Right! In addition to that you cannot use operators like +, -, /, *, IN and { ... } on larger sets implemented as user data types, they are *nonportable* and *inefficient*. Built-in Modula-2 sets are syntactically much better than Pascal's sets. It is unfortunate that they are so poorly implemented. As existing Modula-2 compilers usually don't allow large sets, you cannot even write a (portable) compiler that uses the method of passing sets of stopping symbols as parameters to the parsing procedures. This method is used for error recovery in many Pascal compilers (written in Pascal). And how about being able to say: VAR screen[8000H]: SET OF [0..768*512-1] ? The potential applications of large sets are numerous. > The British Standards Institute Modula-2 Standardisation effort is >working on changing the language definition to open up sets to at least >include enough memebers to define SET OF CHAR. Progress is being made at a >glacial pace on this . . . Sarcastically you could imagine the following reasoning behind this decision: "These one-word sets, aren't they a little too restricting? Let's represent sets as the bits of an *array* of words." "Yes, but let's not generalize too much: surely there must be some upper limit on the size of this array. Shall we say *four* 32-bit words?" The point is: because the size of the set is always known at compile time, the size of this array can also be determined at compile time. If you only use small sets that fit in one word, then you don't even need an array: *no* runtime overhead. Even indexing the array can be efficient, on a 32-bit machine, divide the number of the bit to be tested/included/excluded/etc. by 32, that is, shift the bits five places to the right. And if you are accessing a constant member of the set then you don't even have to do that, the compiler can figure out the address of the word in which to look for the appropriate bit. ----------------------------------------------------------------------- Johan Myreen UUCP: ...!mcvax!hutcs!jem Bistervagen 6 B 416 Bitnet: jem%hutcs.uucp@fingate.bitnet SF-02150 Esbo, Finland Internet: jem@hutcs.hut.fi