[net.lang.mod2] overloading and polymorphism

ken@ROCHESTER.ARPA (Ipse dixit) (03/06/86)

Ok, I'm going to regret posting this, but I'll jump into the fray.

I have seen one Pascal extension proposal that provides optional
arguments, variable length argument lists and polymorphic arguments.
This appeared in Software Practice and Experience in around '79, I
think -  I don't have the copy anymore.

Optional arguments are indicated in the procedure header as:

	procedure writeint ( value : integer; optional flag(width : integer));
	...
	begin
	...
		if flag then
			w := width		(* if width was specified *)
		else
			...
	end;

or something like that, and used thus:

	foo(2); foo(2,6);

The safety comes from the fact that width can only be used inside the
scope of the if.

For variable number of arguments:

	procedure printint ( multiple count (value : integer));
	...
	begin
		while count > 0 do
			write (value);		(* iterates across arguments *)
	...
	end;

For polymorphic arguments:

	procedure put ( choice t (value : type));
	...
	begin
		case t of
		integer:
			...
		real:
			...
	end;

Again value can only be referenced inside the case.

"optional", "multiple" and "choice" will have to be made reserved
words, of course.

I am not enough of a language expert to say if this or some similar
extension will satisfy the needs of I/O modules without introducing
overloading.  Not to mention issues of orthogonality and ease (or even
possibility) of implementation.  Modula-2 already has open arrays,
which implicitly requires passing a hidden argument which is the size
of the array. Can something from that be adapted?

Comments?

	Ken