I have a problem with a code that I found on Internet, I want to make a bitmap and the procedure says:
procedure Put PPM (File : File_Type; Picture : Image) is
But when I call the procedure in the main, I dont know what should I put in the first parameter, a string with the name, the extension or what???
I hope you can help me :)
I’m fairly sure your code comes from Rosetta Code.
This begins
with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
and the File_Type
is defined in Ada.Streams.Stream_IO
(ARM A.12.2).
Your main program will need to declare a variable of type Ada.Streams.Stream_IO.File_Type
, create the file, and pass it to Put_PPM
:
with Ada.Streams.Stream_IO;
with Put_PPM;
procedure My_Main is
F : Ada.Streams.Stream_IO.File_Type;
Pic : ...
begin
Ada.Streams.Stream_IO.Create
(F,
Mode => Ada.Streams.Stream_IO.Out_File,
Name => “foo.ppm”);
Put_PPM (File => F, Picture => Pic);
end My_Main;
(this doesn’t address getting parameters from the command line, handling the case where foo.ppm
already exists, and much more).
Ada is meant to be easy (-ish) to read, at the expense of more effort writing it, and the standard approach to saving readers like you and me from wondering where things are declared is to avoid the ‘use’ clause in (at least) specifications. So the Rosetta example would have been better written
with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO;
procedure Put_PPM (File : Ada.Streams.Stream_IO.File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
use Ada.Streams.Stream_IO;
(and likewise for Image
).