From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 29 Sep 92 05:22:16 GMT 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 Message-ID: <1a8p68INN8ke@huon.itd.adelaide.edu.au> List-Id: 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 # # #######################################################################