Article View: comp.lang.modula2
Article #3836Re: Number of elements in a set
From: news
Date: Thu, 17 Sep 1987 21:59
Date: Thu, 17 Sep 1987 21:59
47 lines
3044 bytes
3044 bytes
>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
Technical Details
Message-ID:
<7528@santra.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!mcvax!enea!tut!santra!newsReferences:
<8709140824.AA21380@cayuga.cs.rochester.edu> <8709142056.AA10394@vulcan.dec.com>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!mcvax!enea!tut!santra!news From: news@santra.UUCP (news) Newsgroups: comp.lang.modula2 Subject: Re: Number of elements in a set Message-ID: <7528@santra.UUCP> Date: Thu, 17-Sep-87 17:59:43 EDT Article-I.D.: santra.7528 Posted: Thu Sep 17 17:59:43 1987 Date-Received: Sun, 20-Sep-87 10:51:41 EDT References: <8709140824.AA21380@cayuga.cs.rochester.edu> <8709142056.AA10394@vulcan.dec.com> Reply-To: jem@hutcs.UUCP (Johan Myreen) Organization: Helsinki University of Technology, Finland Lines: 47