Related articles |
---|
Pascal compiler and sets dallison@bfsec.bt.co.uk (1994-02-08) |
Sets in Pascal, etc. hbaker@netcom.com (1994-02-09) |
Re: Sets in Pascal, etc. andrew@srsune.shlrc.mq.edu.au (1994-02-11) |
Newsgroups: | comp.compilers |
From: | andrew@srsune.shlrc.mq.edu.au (Andrew McVeigh) |
Keywords: | Pascal, Oberon |
Organization: | SHLRC, Macquarie University |
References: | 94-02-051 94-02-061 |
Date: | Fri, 11 Feb 1994 19:32:36 GMT |
hbaker@netcom.com (Henry G. Baker) writes:
> When I taught Pascal, I found sets to be extremely useful, but I also
> found their arbitrary size limitations very irritating.
>
> For twenty years, I have been one of the champions of extending boolean
> operations to Lisp's bignums, which then have the capability of emulating
> any finite (positive) or co-finite (negative numbers) set.
I agree that the limitation on set size is most annoying. However, with
the advent of Object Pascal and Oberon-2, this limitation can be neatly
hidden through the use of a Set object. This means that the compiler can
implement sets using whatever width is most efficient, and the programmer
doesn't have to be constrained by this.
Though the implementation of a Set class (object) is simple, I would like
to point out that the book: "Object Oriented Programming in Oberon-2" by
Hanspeter Mossenboeck contains the code for such a thing. It looks like
the following: (I have modified this slightly)
MODULE Sets;
TYPE
Set* = RECORD
max-: INTEGER; (*largest element*)
val: POINTER TO ARRAY OF SET; (*open-ended array*)
END;
VAR
setSize: INTEGER; (* size of type SET *)
PROCEDURE (VAR s: Set) Init* (max: INTEGER);
BEGIN
s.max := max;
NEW(s.val, (max+setSize) DIV setSize);
END Init;
(* you get the picture *)
(*PROCEDURE (VAR s: Set) CopyTo* (var s1: Set);
[code deleted]
PROCEDURE (VAR s: Set) Clear*;
[code deleted]
PROCEDURE (VAR s: Set) Incl* (x: INTEGER);
[code deleted]
PROCEDURE (VAR s: Set) Excl* (x: INTEGER);
[code deleted]
PROCEDURE (VAR s: Set) Contains* (x: INTEGER);
[code deleted]
PROCEDURE (VAR s: Set) Incl* (x: INTEGER);
[code deleted]
PROCEDURE (VAR s: Set) Add* (s1: Set);
[code deleted]
PROCEDURE (VAR s: Set) Subtract* (s1: Set);
[code deleted]
PROCEDURE (VAR s: Set) Intersect* (s1: Set);
[code deleted]*)
BEGIN (* initialisation for module *)
setSize := MAX(SET) + 1;
END Sets.
Cheers,
Andrew McVeigh
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.