From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.mixmin.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Need some help in Ada Date: Wed, 23 Mar 2016 23:10:10 +0200 Organization: Tidorum Ltd Message-ID: References: <2b215924-fdb7-4f58-b496-018ab837feec@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net HWLh7BS1FyngvZs7DtWngA8Km+y5y+py9qSsM3fphtJgB2Xj7N Cancel-Lock: sha1:hmDxZXPAlVIRhGdUXL15pQycZAg= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:29867 Date: 2016-03-23T23:10:10+02:00 List-Id: 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 . @ .