comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Need some help in Ada
Date: Wed, 23 Mar 2016 23:10:10 +0200
Date: 2016-03-23T23:10:10+02:00	[thread overview]
Message-ID: <dlgf1fFslv9U1@mid.individual.net> (raw)
In-Reply-To: <fee2c972-db94-402c-b2ee-c80fc8dc329b@googlegroups.com>

On 16-03-23 22:24 , danifreecs@gmail.com wrote:
> 2016. március 23., szerda 20:51:40 UTC+1 időpontban Anh Vo a következőt írta:
>> On Wednesday, March 23, 2016 at 12:29:05 PM UTC-7, danif...@gmail.com wrote:
>>> Hello there!
>>>
>>> I'm a student, and i've got my 1st home project in Ada. I need to implement a J_String package with a lot of functions etc, but i have problems at the start. The specification asks me to "implement J_String type as an opaque discriminant record type. For the inner representation of the string use the Standard String type. The discriminant determines the size of the string, which is contained in the J_String type."
>>>
>>> My .ads at the moment:
>>>
>>> package J_String_Pkg is
>>>    type J_String(Size: Natural) is private;
>>>    private
>>>      type J_String(Size: Natural) is record
>>>        Components: String(Natural Range 0..Natural'Last);
>>>        end record;
>>> end J_String_Pkg;
>>>
>>> I don't know if the above is good, but the main reason i'm asking help is the following methods:
>>> function Create(Str : String) return J_String;
>>> --Creates a J_String from a String
>>> function Value_Of(S : J_String) return String;
>>> --Returns the content of S in String type
>>> function Is_Empty(S : J_String) return Boolean;
>>> -- Returns true if, and only if, length() is 0.
>>>
>>> I think i can do the other 20+ methods, but i can't figure out how to make my J_String type to be able to create empty strings. Thanks for every help!
>>
>> Empty string means string length is 0. That means upper string index is less than lower string index. For example, an empty predefined string looks like this.
>>
>> Empty_String : String (1 .. 0) := "";
>>
>> By the way, now you can see why the record field Components is not correct.
>>
>> Anh Vo
>
> Thank you for the reply! So it should be Components: String(1..Size)?
> then i wrote this:
> function Create(Str : String) return J_String is
> 	Jstr: J_String(Str'Length);
> 	begin	
> 		if (Str'Length = 0) then
> 			Jstr.Components := "";
> 		else
> 			Jstr.Components := Str;
> 		end if;
> 	return Jstr;
> 	end Create;
> when i try to use it like: jstr1: J_String(4) := Create("doge");
> i get this error "expected private type ada.text_io.file_type" which i can't really understand.
>

Perhaps -- as a guess -- you have, in your program, a "use Ada.Text_IO", 
but do not have a "use J_String_Pkg". If so, then the subpogram 
Ada.Text_IO.Create is directly visible, but J_String_Pkg.Create is not, 
and perhaps the compiler believes you are calling the subprogram from 
Text_IO, which of course works with File_Type objects, not objects of 
type J_Strings.

Try to write "J_String_Pkg.Create" instead of "Create".

HTH,

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


  parent reply	other threads:[~2016-03-23 21:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 19:29 Need some help in Ada danifreecs
2016-03-23 19:51 ` Anh Vo
2016-03-23 20:24   ` danifreecs
2016-03-23 20:52     ` Anh Vo
2016-03-23 21:11       ` danifreecs
2016-03-23 21:34         ` Anh Vo
2016-03-23 21:06     ` Robert A Duff
2016-03-23 21:10     ` Niklas Holsti [this message]
2016-03-23 21:18 ` danifreecs
replies disabled

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