comp.lang.ada
 help / color / mirror / Atom feed
From: Ehud Lamm <mslamm@mscc.huji.ac.il>
Subject: Re: printf package/Function/Procedure in Ada ??
Date: 1999/03/10
Date: 1999-03-10T00:00:00+00:00	[thread overview]
Message-ID: <Pine.A41.3.96-heb-2.07.990310102211.21452A-100000@pluto.mscc.huji.ac.il> (raw)
In-Reply-To: 36E61F72.4C68BE6C@rocketmail.com

On Wed, 10 Mar 1999, Corey Ashford wrote:

> Tom Moran wrote:
> > 
> > Isn't
> >   Put("I=" & integer'image(i) & name);
> > simpler than
> >   printf("I=%i%s", i, name);
> 
> Except that printf allows you to more easily get fancy with formatting of
> the variables, e.g. %08x, or %7.3f.  You can do this kindof thing with
> text_io, but it's a lot more keystrokes.
> 
> In general, I think formatted I/O is a little more difficult in Ada, but Ada provides
> many things that C can't do easily or at all (e.g. string slices, 'image for enumerated
> types).
> 

I think the real problem is input not output. In Ada you have to "parse"
fileds in the input semi manually, where as scanf does it for you. I know
scanf sucks in many respects, but sometimes its behind the scenes work is
very valuable.

Writing scanf in Ada is conceptually problematic - since as opposed to
output, in input you really don't have any clues as to the types that may
exist in the input stream.

My best conceptual solution (this means I haven't really coded it yet) is
to have something like this:

Int1:=To_Integer(Get_Field(<field characteristics>))

Where Get_Field is overloaded by type but all other params (like width)
are standard. It always returns String (or something like it). The
conversion stays the responsibility of the caller.

Better ideas are more than welcome.

Ehud Lamm     mslamm@pluto.mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm     <== Use PURL to find me!





  reply	other threads:[~1999-03-10  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-09  0:00 printf package/Function/Procedure in Ada ?? solo
1999-03-10  0:00 ` Tom Moran
1999-03-10  0:00   ` Corey Ashford
1999-03-10  0:00     ` Ehud Lamm [this message]
1999-03-10  0:00 ` robert_dewar
1999-03-10  0:00 ` Richard D Riehle
1999-03-10  0:00 ` dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox