Thread View: comp.lang.modula2
1 messages
1 total messages
Started by David Hiebeler
Mon, 17 Aug 1987 17:17
Generic procedures
Author: David Hiebeler
Date: Mon, 17 Aug 1987 17:17
Date: Mon, 17 Aug 1987 17:17
30 lines
2056 bytes
2056 bytes
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!"
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads