[net.lang.mod2] VARARGs

bobc@tikal.UUCP (Bob Campbell) (03/11/86)

The is (and has been for some time) a debate about implementing
varable arguments handling in modula-2.  So to insure that my ideas
are heard I summit the following suggestion:

Why not use a Macro preprocessor to implement this feature.  This
type of system could handle most of the things required by the
I/O systems:

For example

MACRO PrintF(control:STRING,VARS:LIST);
VAR
    tmp:	STRING;
    i,element:	INTEGER;
BEGIN
    element := 0;
    i := 0
    WHILE i <= HIGH(control) DO
	IF (control[i] = '%') THEN
	    IF (tmp <> "") THEN WriteString(tmp) END;
	    IF (element > HIGH(list)) THEN
		ERROR('Missing Parameter');
		RETURN;
	    END;
	    INC(i);
	    CASE (control[i]) OF
	    'c':
		WriteChar(LIST[element]);
	    ....
	    END;
	ELSE
	    APPEND(control[i],tmp);
	END;
	INC(i)
    END;
    IF (tmp <> "") THEN WriteString(tmp) END
END PrintF;

Now if this "Macro" is executed at compile time you have a printf which
will detect type errors at compile time.  This also can work like NEW,
and DISPOSE as the programmer can select where Write... is imported
from.

One advantage of this Idea is that if you write this preprocessor then
you can make money selling it to people like me who would like to add
these types of features to a compiler that I already have.

The syntax etc is not well worked out (not yet maybe someday) but this
could create a portable extention to the language.

Bob Campbell
Teltone Corp.
Kirkland Wa.
{amc,dataio,fluke,uw-beaver}!tikal!bobc

ken@rochester.UUCP (Ipse dixit) (03/15/86)

I like macro processors for some things but there are at least 2
caveats:

1. Unless standardized, the macro extensions make portability harder.

2. Relating error messages from the compiler to the original source can
be a problem.

	Ken
-- 
UUCP: ..!{allegra,decvax,seismo}!rochester!ken ARPA: ken@rochester.arpa
Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!