Do I have to create a dummy file to satisfy the compiler? ;)

15 views
Skip to first unread message

Curly

unread,
Nov 30, 2019, 1:22:38 PM11/30/19
to Eiffel Users
I am iterating across a list of items, whose names are used to create files.

The compiler insists that I initialise the PLAIN_TEXT_FILE object before I enter the loop.

Does this mean that I have to create a dummy file pre-loop just to satisfy the compiler, or is there another way?

Alexander Kogtenkov

unread,
Nov 30, 2019, 3:33:44 PM11/30/19
to eiffel...@googlegroups.com
Would you share the code with the issue, please?
 
Alexander Kogtenkov
 
 
Суббота, 30 ноября 2019, 21:22 +03:00 от Curly <gimmean...@gmail.com>:
 
I am iterating across a list of items, whose names are used to create files.
 
The compiler insists that I initialise the PLAIN_TEXT_FILE object before I enter the loop.
 
Does this mean that I have to create a dummy file pre-loop just to satisfy the compiler, or is there another way?

 

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/a3c9f611-80f4-47f0-bae5-8e4de53dbc47%40googlegroups.com.

 

Curly

unread,
Nov 30, 2019, 4:46:42 PM11/30/19
to Eiffel Users
Hi Alexander,

I thought it self-explanatory, but when I came to put an example together for you, I realised it wasn't!

Here's the 'bad' code:

    ml_filename: STRING
    ml_output_file
: PLAIN_TEXT_FILE

    make
       
local
            division_list
: ARRAY[STRING]

       
do
            division_list
:= << "E0", "E1" >>


            ml_filename
:= ""
--          create ml_output_file.make_create_read_write ("C:\Dummy_file.csv")


            across division_list
as division_entry
            loop
                ml_filename
:= "C:\Example\" + division_entry.item.out + "\real_file.csv"
                create ml_output_file.make_open_write (ml_filename)

                ml_output_file.close
            end -- division_list loop
        end -- make



This will only work as-is if you uncomment the dummy file creation.

I have now noticed, however, that if the file descriptors are made local instead of global it works as I intended.

------------------------------------------------------------------------------------------------------

On Saturday, 30 November 2019 20:33:44 UTC, Alexander Kogtenkov wrote:
Would you share the code with the issue, please?
 
Alexander Kogtenkov
 
 
Суббота, 30 ноября 2019, 21:22 +03:00 от Curly <gimmean...@gmail.com>:
 
I am iterating across a list of items, whose names are used to create files.
 
The compiler insists that I initialise the PLAIN_TEXT_FILE object before I enter the loop.
 
Does this mean that I have to create a dummy file pre-loop just to satisfy the compiler, or is there another way?

 

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users+unsubscribe@googlegroups.com.

Bertrand Meyer

unread,
Dec 1, 2019, 4:32:56 PM12/1/19
to eiffel...@googlegroups.com, me...@inf.ethz.ch

ml_output_file is an attribute. Since it is declared as attached, every creation procedure has to make sure it is non-void on exit of the procedure (i.e. on start of the object’s life).

 

The loop could be executed zero times. In that case, without the commented-out line, the attribute would be void.

 

-- BM

To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.


 

--

You received this message because you are subscribed to the Google Groups "Eiffel Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/f972a519-4ae1-4471-9f09-d46b87425311%40googlegroups.com.

Curly

unread,
Dec 2, 2019, 10:26:34 AM12/2/19
to Eiffel Users
Thanks for the clarification, Bertrand.

Even though it's in the basics, I hadn't paid attention to attached and detachable. If I'd spotted that earlier it would have saved me a lot of trouble!

-------------------------------------------------------------------------------------------

To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to eiffel...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages