comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@shell5.ba.best.com>
Subject: Re: Announce: OpenToken 2.0 released
Date: 2000/02/01
Date: 2000-02-01T00:00:00+00:00	[thread overview]
Message-ID: <Pine.BSF.4.21.0002011210100.9470-100000@shell5.ba.best.com> (raw)
In-Reply-To: 87799k$aai1@news.cis.okstate.edu

On 1 Feb 2000, David Starner wrote:
> On 01 Feb 2000 13:16:14 -0500, Hyman Rosen <hymie@prolifics.com> wrote:
> >By the way, the normal C/C++ style for handling EOF is to have the
> >return type of the character reader be such that it can hold any
> >value of the character set, plus an out-of-band value representing
> >EOF. The usual is '#define EOF -1' and 'int getchar()'.
> 
> Which means that c: Character; c := getchar(); is illegal (at least
> in Ada; in C it would get silently truncated.) It's a major pain
> in C, and a well known source of bugs. How about making it like
> procedure GetChar (EOF: in out boolean; Char: in out character);?

There are a few other approaches I can think of to this issue

(1) Exceptions: raise a Not_Found when input is exhausted. Some people 
    hate this because "Exceptions are only for error handling, not
    control flow!". OCaml (and SML too I think) use exceptions for this, 
    and Ada sometimes does (try reading a file stream without using
    File_Type...)

(2) Provide a query on the sequence, like in Java, so you have code like 

    while Has_More_Elements(Seq) loop 
        Char := Get_Next_Element(Seq);
        ...
    end loop;

    I find this very readable.

(3) Provide an option type like in (OCa|S)ML which wraps returned elements 
    and forces the reader to unwrap them, like this 

    type Option_T is (Some, None);

    generic
        type Element_T is private;
    package Options is
      type Optional_T(Option : Option_T) is record
          case Option is
             when Some =>
                 Data : Element_T;
             when None  =>
                 null;
          end case;
      end record;
    end Options;

   loop 
        Elem := Get_Next_Element(Seq);
        case Elem.Option is 
            when Some => ...
            when None => exit;
        end case;
  end loop;

This is too inefficient for reading chars and is very verbose in Ada; much
less so in ML.

-- Brian






  reply	other threads:[~2000-02-01  0:00 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-27  0:00 Announce: OpenToken 2.0 released Ted Dennison
2000-01-28  0:00 ` Jürgen Pfeifer
2000-01-28  0:00   ` Ted Dennison
2000-01-31  0:00 ` Hyman Rosen
2000-02-01  0:00   ` Ted Dennison
2000-02-01  0:00     ` Hyman Rosen
2000-02-01  0:00       ` David Starner
2000-02-01  0:00         ` Brian Rogoff [this message]
2000-02-01  0:00           ` Hyman Rosen
2000-02-01  0:00             ` Brian Rogoff
2000-02-02  0:00               ` Hyman Rosen
2000-02-02  0:00             ` Jeff Carter
2000-02-02  0:00             ` Vladimir Olensky
2000-02-01  0:00               ` Hyman Rosen
2000-02-02  0:00       ` Ted Dennison
2000-02-04  0:00         ` Ted Dennison
2000-02-05  0:00           ` Ehud Lamm
2000-02-04  0:00       ` Florian Weimer
2000-02-07  0:00         ` Hyman Rosen
2000-02-07  0:00           ` Florian Weimer
2000-02-07  0:00             ` Hyman Rosen
2000-02-09  0:00           ` Robert A Duff
2000-02-09  0:00             ` Hyman Rosen
2000-02-09  0:00               ` Larry Kilgallen
2000-02-17  0:00               ` Robert A Duff
2000-02-17  0:00                 ` Hyman Rosen
2000-02-17  0:00                   ` Hyman Rosen
2000-02-17  0:00                     ` Robert A Duff
2000-02-17  0:00                       ` Hyman Rosen
2000-02-17  0:00                   ` Robert A Duff
     [not found]                   ` <88iuk2$s6d3@ftp.kvaerner.com>
2000-03-05  0:00                     ` [OT] C and in-band signalling (was: Re: Announce: OpenToken 2.0 released) Florian Weimer
2000-03-06  0:00                       ` Tarjei T. Jensen
2000-03-06  0:00                         ` Keith Thompson
replies disabled

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