comp.lang.ada
 help / color / mirror / Atom feed
From: munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!cs.adelaide.edu.au! andrewd@uunet.uu.net  (Andrew Dunstan)
Subject: Re: Ada's (in)visibility in the engineering community
Date: 29 Sep 92 05:22:16 GMT	[thread overview]
Message-ID: <1a8p68INN8ke@huon.itd.adelaide.edu.au> (raw)

In article <1750@aviary.Stars.Reston.Unisys.COM>, dmarshal@Stars.Reston.Unisys.
COM (Dave Marshall) writes:
|> In article <1a0ijeINNfei@huon.itd.adelaide.edu.au>, andrewd@cs.adelaide.edu.
au (Andrew Dunstan) writes:

|> > 
|> >   with text_io; use text_io;
|> >   with unchecked_conversion;
|> >   procedure file_conv is
|> > 
|> Ack! A totally UNJUSTIFIED use of UNCHECKED_CONVERSION!  Flagellate yourself
|> thrice daily for a week.
|>

I did say it was a hack. I did ask how to do it otherwise.
 

|> > (1) APART from any righteous feelings about breaking the language's
|> > privacy mechanism, are there any good reasons for not doing something
|> > like this?
|> 
|> Yes.  Don't used UNCHECKED_CONVERSION if you don't have to.
|>

Read the question again.
 
|> > 
|> > (2) Is there a better way to do it, one which does not rely on this
|> > sort of hack?
|> 
|> Yes. Access types.  A simple example follows at the end of this response.
|> 

|> 
|> with TEXT_IO;
|> 
|> procedure FILE_TEST is
|> 
|>   type FILE_POINTER is access TEXT_IO.FILE_TYPE;
|> 
|>   type POINTERS is array ( INTEGER range <>) of FILE_POINTER;
|> 
|>   MY_ARRAY   : POINTERS(1..5);
|> 
|>   SOME_NAMES : constant array (INTEGER range 1..5) of STRING(1..8) :=
|>     ( "myfile.1",
|>       "myfile.2",
|>       "myfile.3",
|>       "myfile.4",
|>       "myfile.5");


This won't work for what I want to do. I want to be able to stack the
current input, whatever that might be (including, possibly, standard_input).

What good to me is a pointer to something that I can't assign in the first 
place?

Arthur Evans (ae@sei.cmu.edu) wrote
|> andrewd@cs.adelaide.edu.au (Andrew Dunstan) asks about a stack of items
|> of type Text_IO.File_Type, which is limited private.
|>
|> It would be hard to do if you are using a stack package.  However, if
|> you implement the stack as an array and an index (probably reasonable in
|> your case), just open the file right into the stack.  Leaving out a lot,
|> like this:
|>
|>      File_Stack: array(0..File_Stack_Max) of Text_IO.File_Type;
|>      Current_File: integer := 0;     -- Current item in File_Stack


This won't work either, for the same reason.



here's what I want to be able to do, whether or not I use a stacks
package or an explicit array:


function include(file_name : string) return boolean is
   ifile : file_type;
begin
   open(ifile,in_file,file_name);
   push(some_expression(current_input));
   set_input(ifile);
   return true;
exception
   when others => return false;
end;

function yywrap return boolean is
begin
   if empty_stack then
      return true;
   else
      close_file(current_input);
      set_input(some_other_expression(top_of_stack));
      pop_stack;
      return false;
   end if;
end;


I suspect it is not possible to do using good coding practices, but I would 
like to know, and not just from idle curiosity.


-- 
#######################################################################
#  Andrew Dunstan                   #   There's nothing good or bad   #
#  Department of Computer Science   #   but thinking makes it so.     #
#  University of Adelaide           #                                 #
#  South Australia                  #          - Shakespeare          #
#  net: andrewd@cs.adelaide.edu.au  #                                 #
#######################################################################

             reply	other threads:[~1992-09-29  5:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-09-29  5:22 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!cs.adelaide.edu.au! [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-10-06 18:32 Ada's (in)visibility in the engineering community Bob Kitzberger
1992-10-06 15:22 David Erickson
1992-10-06  7:27 mcsun!news.funet.fi!network.jyu.fi!sakkinen
1992-10-05 21:54 To ny Wen Hsun Lai
1992-10-05 21:49 David Emery
1992-10-05 19:50 Val Kartchner
1992-10-02  6:24 zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cm
1992-10-01  4:11 Michael Feldman
1992-09-30 13:11 Dag Bruck
1992-09-29 14:41 fred j mccall 575-3539
1992-09-29 13:18 agate!doc.ic.ac.uk!uknet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
1992-09-28 21:23 Ed Schonberg
1992-09-25 21:04 Val Kartchner
1992-09-25 14:35 KMRODGERS
1992-09-21  1:37 pacbell.com!well!well.sf.ca.us!jcc
1992-09-21  0:54 sybus.sybus.com!myrddin!tct!psycho!f310.n3603.z1.FIDONET.ORG!Randy.Baer
1992-09-14 23:23 Pascal Obry
1992-09-14 20:34 Pascal Obry
1992-09-14 16:40 Pascal Obry
1992-09-14 16:03 fred j mccall 575-3539
1992-09-14 15:13 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!caen!nigel.msen.com!yale.edu
1992-09-11 21:46 Harry Koehnemann
replies disabled

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