🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.mod2
Article #306

overloading and polymorphism

#306
From: Ipse dixit
Date: Thu, 06 Mar 1986 17:06
63 lines
2216 bytes
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
Technical Details
Message-ID: <8603061657.29718@ur-seneca.rochester.arpa>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!info-modula-2

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!info-modula-2
From: ken@ROCHESTER.ARPA (Ipse dixit)
Newsgroups: net.lang.mod2
Subject: overloading and polymorphism
Message-ID: <8603061657.29718@ur-seneca.rochester.arpa>
Date: Thu, 6-Mar-86 12:06:58 EST
Article-I.D.: ur-senec.8603061657.29718
Posted: Thu Mar  6 12:06:58 1986
Date-Received: Sat, 8-Mar-86 04:39:20 EST
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 63