comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: put a character back to the input stream
Date: 1999/10/24
Date: 1999-10-24T00:00:00+00:00	[thread overview]
Message-ID: <7uuvac$9be$1@nnrp1.deja.com> (raw)
In-Reply-To: 7ut91r$nih@drn.newsguy.com

In article <7ut91r$nih@drn.newsguy.com>,
  nabbasi@pacble.net.NOSPAM wrote:
> package  Interfaces.C_Streams has function :
>
>   function ungetc (c : int; stream : FILEs) return int;
>
> (and all the other standard C stream functions.)

Yes, you could use this, but it is hard work (and of course
GNAT-specific). You have to use the special functions provided
in GNAT to extract the stream identifier from a Text_IO file
(these are very useful in such situations, see the GNAT
reference manual for details). But really this is entirely
the wrong direction, and is a consequence of following an
incorrect suggestion of how to solve the original problem.

The proper response to the original question is to use
Text_IO.Look_Ahead, which is the standard facility provided
to solve this problem. In Ada, rather than read the character
and unread it (which is a bit of a kludgy concept, and there
are typically limitations on how many times unread can be
called), the paradigm is to look ahead at the next character
without consuming it. This will solve your problem in a
perfectly neat way, neater than the corresponding C, since
you won't need to remember to do an ungetc.

During the design, the veiwpoint was that look ahead was a
better way to provide the required underlying functionality
for solving problems of exactly this kind than the "unread"
approach.

Anyway, thanks for describing not only the solution you were
seeking (unread) but also the underlying problem (figuring
out what to read next). That allows us to give the appropriate
response.

Robert Dewar


Sent via Deja.com http://www.deja.com/
Before you buy.




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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-23  0:00 put a character back to the input stream Frank Shixiang Yan
1999-10-23  0:00 ` nabbasi
1999-10-24  0:00   ` Robert Dewar [this message]
1999-10-25  0:00 ` Ted 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