comp.lang.ada
 help / color / mirror / Atom feed
From: danifreecs@gmail.com
Subject: Re: Need some help in Ada
Date: Wed, 23 Mar 2016 13:24:03 -0700 (PDT)
Date: 2016-03-23T13:24:03-07:00	[thread overview]
Message-ID: <fee2c972-db94-402c-b2ee-c80fc8dc329b@googlegroups.com> (raw)
In-Reply-To: <2b215924-fdb7-4f58-b496-018ab837feec@googlegroups.com>

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.


  reply	other threads:[~2016-03-23 20:24 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 [this message]
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
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