Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!lll-lcc!unisoft!jef
From: jef@charming.uucp (Jef Poskanzer)
Newsgroups: comp.lang.misc
Subject: Re: Check the Arg Count
Message-ID: <198@unisoft.UUCP>
Date: Mon, 5-Jan-87 21:25:54 EST
Article-I.D.: unisoft.198
Posted: Mon Jan  5 21:25:54 1987
Date-Received: Tue, 6-Jan-87 02:43:37 EST
References: <3101@diamond.Diamond.BBN.COM> <193@unisoft.UUCP>
Sender: news@unisoft.UUCP
Reply-To: jef@charming.UUCP (Jef Poskanzer)
Organization: Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal
Lines: 53

[In response to my article, I received the following e-mail message.
Unfortunately, some host, probably amdahl, munged the path, so I can't
reply to it.  (There is no user "mdash" on amdahl.)  Since the subject
is within the bounds of newsgroup discussion, I am taking the liberty
of replying via news.]

>Date: Wed, 31 Dec 86 07:59:00 EST
>From: lll-lcc!seismo!amdahl!mdash (45415-M.D.Scheer(mhB624)mhB624)
>Message-Id: <8612311259.AA06480@amdahl>
>To: jef@unisoft
>Subject: Re: Check the Arg Count
>Newsgroups: comp.lang.misc
>Organization: AT&T Information Systems, Summit, N. J.
>
>>(2) Bullshit.  I found it very easy to write a printf-clone in Mesa.
>>I used variant records for the data, so that the compiler did most
>>of the type-checking work, and I got variable numbers of arguments
>>by using defaulting parameters.  No problem at all for a Real Man's
>>Language.
>
>Interesting.  I am only passingly familiar with Mesa, but have worked
>extensively with Ada (Let's omit the scatological comments for the
>moment), and have concluded that one cannot duplicate the flexibility
>of printf in Ada without either escaping from type-checking.  How did
>you avoid an exhaustive listing of all permitted argument combinations
>in your variant record type definition?  How bad is the data space over-
>head of you implementation?


The way it worked is that each data item was a separate variant record,
so I didn't have to list "all permitted argument combinations" - just
all the different types that could be formatted.  A sample call:

  PF.Put["line number = %g, line = \"%g\"\n"L, card[linnum], str[line]];

The card[...] and str[...] are record constructors.  (Actually, they are
inline procedures that return discriminated variant records.  A true
record constructor would have another set of [] around it.  Probably the
compiler could be made smart enough so that you could just use the variable
name without any [] bullstuff, but currently it's not.)  The %g means
"general" - since the type of the data item is known already, there is no
need to specify it in the format string.

As for data space overhead - by the only measure that matters, it's negative.
When I wrote this package, I converted a few system utilities to use it.
The size of the compiled binaries decreased by up to 30%.
---
Jef

			     Jef Poskanzer
		    unisoft!jef@ucbvax.Berkeley.Edu
			 ...ucbvax!unisoft!jef
			     (415)644-1230