Article View: comp.lang.modula2
Article #168Re: Size of sets
From: Johan Myreen
Date: Tue, 11 Jul 1989 13:42
Date: Tue, 11 Jul 1989 13:42
59 lines
3654 bytes
3654 bytes
In article <990@maestro.htsa.aha.nl> fransvo@maestro.htsa.aha.nl (Frans van Otten) writes:
Yesterday I went to the first Dutch ISO-meeting on standardizing
Modula-2. I got a copy of the "First Working Draft Modula-2
Standard", from the British Standards Institution. It states
about set types:
"The base type of the set type shall be an ordinal type".
I think this settles all problems. Also, it is proposed that
an implementation should at least support SET OF CHAR. (A
small problem was mentioned: Chinese etc. character sets are
rather big...)
I don't see any problem with that. I really don't understand why you
should stop at SET OF CHAR? What is so special about 16 bytes that
makes it more difficult to represent SETs using more bytes than that?
Why not at the same time restrict array indices to some subrange, say
0..1023, or allow at most three-dimensional arrays? Restricting the base
types of sets sounds just as stupid to me.
SET OF INTEGER, for instance, is a perfectly reasonable data type.
Probably exactly the same machine code is generated from a statement
accessing an element in such a set as is generated from accessing an
element from a set of type SET OF CHAR. In both cases you have to
first calculate an offset into an array of bytes (or words) and then
fetch the bit corresponding to the referenced element.
The beutiful thing about Modula-2 sets (at least from a compiler
writers point of view) is that the type and size of every set variable
and set literal are known at compile time. This means that small sets,
which fit in a word, can be implemented quite efficiently. It also
means that allowing SET OF INTEGER does not affect the efficiency of
a relatively small set like SET OF CHAR, even if huge sets would require
more expensive instructions. The situation is analoguos to big arrays
vs. small arrays: small arrays may be indexed more efficiently on some
architectures but that is no reason to prohibit big arrays, is it?
(The type of a set literal had to be declared last time I looked. You
aren't changing that, are you?? I agree it looks nice to write
IF ch IN ['A'..'Z'] THEN ... like in Pascal, but that has really got
nothing to do with the mathematical concept of a set, and is, in my
opinion, an ugly hack.)
A variable of type SET OF INTEGER probably even fits in the memory of
a 16-bit computer. And even if it doesn't fit, that is just as much a
reason to ban them as there is reason to ban big arrays for not
fitting in the memory of some computer. Althoug I said earlier that
big sets may require more expensive instructions (which probably isn't
even true on most machines) I can't see why they would be more
difficult to implement, probably just as much work as handling the
restriction that they can't be larger than SET OF CHAR.
So prove me wrong. If there is a reason for restricting the
size of a Modula-2 set, other than that of insufficient memory, I
would very much like to hear it.
(* Johan Myreen *)
(* jem@spica.hut.fi *)
Technical Details
Message-ID:
<JEM.89Jul11164236@sauna.HUT.FI>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!kth!draken!tut!santra!jemReferences:
<6328@pdn.paradyne.com> <990@maestro.htsa.aha.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!kth!draken!tut!santra!jem From: jem@sauna.HUT.FI (Johan Myreen) Newsgroups: comp.lang.modula2 Subject: Re: Size of sets Message-ID: <JEM.89Jul11164236@sauna.HUT.FI> Date: 11 Jul 89 13:42:36 GMT References: <6328@pdn.paradyne.com> <990@maestro.htsa.aha.nl> Sender: news@santra.UUCP Organization: Helsinki University of Technology, Finland Lines: 59 In-reply-to: fransvo@maestro.htsa.aha.nl's message of 30 Jun 89 13:12:41 GMT