[comp.lang.modula2] Generic procedures

hiebeler@csv.rpi.edu (David Hiebeler) (08/17/87)

References:

Keywords:


After using Pascal, one of the features I especially enjoy about Modula-2
is the ability to write more generic procedures.  For example, a proc which
recieves an ARRAY OF CHAR, of whatever length.  Or, if you want to get a 
little deeper, one which recieves an ARRAY OF WORD so that the proc may
use REALS, INTEGERS, CARDINALS, or whatever.
  My Stack module imports the DataType to be stored in the stack from a
module called TypeOfData which simply exports a transparent type.  Then,
the module which is calling the Stack module may also import DataType and
declare vars of that type, etc. (If DataType is opaque, you can't do things
like send vars of that type to WriteInt, even if DataType is declared as
INTEGER).
  These things are much better than Pascal as far as data abstraction goes.
However, give me an inch and I want a kilometer.  Now I find that I want to
write a WriteInt procedure, for example, that recieves a File parm stating
where the output will go, an INTEGER to output, and OPTIONALLY a fieldwidth
specifier.  No such luck.  I don't know of any ways, no matter how tricky,
to write a procedure that can recieve a variable number of parameters.
Any ideas?  Right now, I have 2 procs: WriteInt, and WriteIntf (formatted),
and similarly for other data types (REALS, etc.).

                             -D.H.
----
David Hiebeler       hiebeler@csv.rpi.edu
Chatham, NY         "Illusions, Richard!  Every
(also Troy, NY)      bit of it illusions!"