* Re: A question and a request [not found] <3BE93E12.7BB33908@worldnet.att.net> @ 2001-11-07 17:38 ` Eric Merritt 0 siblings, 0 replies; 9+ messages in thread From: Eric Merritt @ 2001-11-07 17:38 UTC (permalink / raw) To: comp.lang.ada Jim, Thanks you, I don't expect to be alot of trouble. I have, from past experience, found out how hard it is to learn to do something correctly without anyone with experience around for a guide. I decided to port a java gui toolkit named Subartic to Ada as my first project, since I have the source for Subartic and permission to port it, it should be fairly easy. In any case, I already have a few simple sources available namly Dimension, Point, and Rectangle. They are pretty small, once I get the changes made that this last discussion has brought about I would like to show them too you. Once again, thank you very much, I did not actually expect anyone to volunteer. Thank You Eric --- James Rogers <jimmaureenrogers@worldnet.att.net> wrote: > Eric, > > I see you have already gotten an explanation of how > subtypes work. > > I am willing to act as a quasi-mentor for your Ada > st;udies. I have > been studying and programming in Ada since 1994. > That does not make > me the most qualified from comp.lang.ada, but I do > think I can help. > > I have been programming in C since 1981. I also know > Java, and have > some familiarity with Perl. > > Jim Rogers > Colorado Springs, Colorado USA > > Eric Merritt wrote: > > > > > > My request is a bit simpler, is there any one out > > there willing to serve as kind of a quasi-mentor. > > Basically look at some simple code occasionally > and > > tell me when I am getting bad habits. I have found > > when learning other languages without experienced > > input that I am able to pick up the language in a > few > > weeks or months and then it takes me a couple of > years > > to realize I have bad habits and attempt to > rectify > > them. This shouldn't be too time consuming for the > > volunteer. I have been programming in other > languages > > professionally (C/C++, Java, Perl and Python) and > I > > have a good understanding of the theory. I just > need > > someone to occasionally look and say "hey this is > > stupid, in Ada do it this way" or "In Ada its > better > > to take this approach". I could post stuff to the > list > > but this seams to be poor etiquette. > > > > In any case, if I get an answer to my first > question I > > will be happy. Thanks > > > > __________________________________________________ > > Do You Yahoo!? > > Find a job, post your resume. > > http://careers.yahoo.com > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: List Container Straw Man @ 2001-11-06 23:52 Nick Roberts 2001-11-07 4:44 ` A question and a request Eric Merritt 0 siblings, 1 reply; 9+ messages in thread From: Nick Roberts @ 2001-11-06 23:52 UTC (permalink / raw) Stephe, how do I e-mail you? -- Nick Roberts ^ permalink raw reply [flat|nested] 9+ messages in thread
* A question and a request 2001-11-06 23:52 List Container Straw Man Nick Roberts @ 2001-11-07 4:44 ` Eric Merritt 2001-11-07 11:00 ` Preben Randhol ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: Eric Merritt @ 2001-11-07 4:44 UTC (permalink / raw) To: comp.lang.ada As some of you may know I am fairly new to Ada and I just found out something that surprised me. I declared two subtypes of an integer. I was then able to add these two types together and assign the result to an instance of one of the above subtypes. or subtype type_1 is Integer; subtype type_2 is Integer; type_1_instance : type_1; type_2_instance : type_2; type_1_instance_2 : type_1; type_1_instance := 1; type_2_instance := 2; type_1_instance_2 := type_1_instance + type_2_instance; The addition operator is taking two disparate but related types and adding them. This is fine, up-casting is a normal thing. However, when the result is returned it is not (should not be?) an instance of the subtype. It seems that the compiler is down-casting automatically. This bothers me and it seams that is violates Ada's strong typing. What am I missing here? My request is a bit simpler, is there any one out there willing to serve as kind of a quasi-mentor. Basically look at some simple code occasionally and tell me when I am getting bad habits. I have found when learning other languages without experienced input that I am able to pick up the language in a few weeks or months and then it takes me a couple of years to realize I have bad habits and attempt to rectify them. This shouldn't be too time consuming for the volunteer. I have been programming in other languages professionally (C/C++, Java, Perl and Python) and I have a good understanding of the theory. I just need someone to occasionally look and say "hey this is stupid, in Ada do it this way" or "In Ada its better to take this approach". I could post stuff to the list but this seams to be poor etiquette. In any case, if I get an answer to my first question I will be happy. Thanks __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 4:44 ` A question and a request Eric Merritt @ 2001-11-07 11:00 ` Preben Randhol 2001-11-07 12:54 ` David C. Hoos, Sr. 2001-11-07 13:24 ` Eric Merritt 2001-11-07 13:58 ` James Rogers ` (2 subsequent siblings) 3 siblings, 2 replies; 9+ messages in thread From: Preben Randhol @ 2001-11-07 11:00 UTC (permalink / raw) On Tue, 6 Nov 2001 20:44:19 -0800 (PST), Eric Merritt wrote: > As some of you may know I am fairly new to Ada and I > just found out something that surprised me. I declared > two subtypes of an integer. I was then able to add > these two types together and assign the result to an > instance of one of the above subtypes. or > > subtype type_1 is Integer; > subtype type_2 is Integer; > > type_1_instance : type_1; > type_2_instance : type_2; > type_1_instance_2 : type_1; > > type_1_instance := 1; > type_2_instance := 2; > type_1_instance_2 := type_1_instance + > type_2_instance; > > The addition operator is taking two disparate but > related types and adding them. This is fine, > up-casting is a normal thing. However, when the result > is returned it is not (should not be?) an instance of > the subtype. It seems that the compiler is > down-casting automatically. This bothers me and it > seams that is violates Ada's strong typing. What am I > missing here? Use type not subtype if you do not want the above behavior. Read below (taken from: http://goanna.cs.rmit.edu.au/~dale/ada/aln/4_basic_types.htmli ) Subtypes We can restrict the range of values a variable can take by declaring a subtype with a restricted range of values (this corresponds to Pascal's user defined types). Any attempt to place an out-of-range value into a variable of a subtype results in an exception (program error). In this way program errors can be discovered. The syntax for a subtype declaration is subtype Name is Base_Type; subtype Name is Base_Type range lowerbound . . upperbound; Examples of declaring subtypes are given below. type Processors is (M68000, i8086, i80386, M68030, Pentium, PowerPC); subtype Old_Processors is Processors range M68000..i8086; subtype New_Processors is Processors range Pentium..PowerPC; subtype Data is Integer; subtype Age is Data range 0 . . 140; subtype Temperatures is Float range -50.0 .. 200.0; subtype Upper_Chars is Character range 'A' .. 'Z'; Subtypes are compatable with their base types . They can be placed in the same place as any variable of the base type can. Also variables of different subtypes that are derived from the same base type are compatable. My_Age : Age; Height : Integer; Height := My_Age; -- silly, but never causes a problem. My_Age := Height; -- will cause a problem if height's -- value is outside the range of -- my_age (0..140), but still -- compilable. Preben -- Please, stop bombing civilians in Afghanistan. One cannot write off killing innocent children and other civilians as "collateral damage". A civilian is a civilian whether he or she is American or from another country in the world. http://web.amnesty.org/11september.htm ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 11:00 ` Preben Randhol @ 2001-11-07 12:54 ` David C. Hoos, Sr. 2001-11-08 2:35 ` dale 2001-11-07 13:24 ` Eric Merritt 1 sibling, 1 reply; 9+ messages in thread From: David C. Hoos, Sr. @ 2001-11-07 12:54 UTC (permalink / raw) To: comp.lang.ada; +Cc: Dale Stanbrough, randhol, cyberlync ----- Original Message ----- From: "Preben Randhol" <randhol+abuse@pvv.org> Newsgroups: comp.lang.ada To: <comp.lang.ada@ada.eu.org> Sent: November 07, 2001 5:00 AM Subject: Re: A question and a request <snip> > Use type not subtype if you do not want the above behavior. Read > below (taken from: > http://goanna.cs.rmit.edu.au/~dale/ada/aln/4_basic_types.htmli ) > > Subtypes > > We can restrict the range of values a variable can take by declaring a > subtype with a restricted range of values (this corresponds to Pascal's > user defined types). Any attempt to place an out-of-range value into a > variable of a subtype results in an exception (program error). In this > way program errors can be discovered. The syntax for a subtype > declaration is > The above paragraph is simply wrong. The excetpion which will be raised is not Program_Error, but Constraint_Error. As a further note to Dale (the prsumed author of the linked website), there are spelling errors in the commentary on those pages. <snip> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 12:54 ` David C. Hoos, Sr. @ 2001-11-08 2:35 ` dale 0 siblings, 0 replies; 9+ messages in thread From: dale @ 2001-11-08 2:35 UTC (permalink / raw) comp.lang.ada@ada.eu.org wrote: > The above paragraph is simply wrong. The excetpion which will be > raised is not Program_Error, but Constraint_Error. :-) it says that an exception is a program error, not that the the exception raised is called Program_Error. Dale ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 11:00 ` Preben Randhol 2001-11-07 12:54 ` David C. Hoos, Sr. @ 2001-11-07 13:24 ` Eric Merritt 1 sibling, 0 replies; 9+ messages in thread From: Eric Merritt @ 2001-11-07 13:24 UTC (permalink / raw) To: comp.lang.ada I knew I was missing something. That actaully make sense, I guess I was getting this typeing behavior mixed up with the OO inheritence model. Thank You, Eric Merritt --- Preben Randhol <randhol+abuse@pvv.org> wrote: > On Tue, 6 Nov 2001 20:44:19 -0800 (PST), Eric > Merritt wrote: > > As some of you may know I am fairly new to Ada and > I > > just found out something that surprised me. I > declared > > two subtypes of an integer. I was then able to add > > these two types together and assign the result to > an > > instance of one of the above subtypes. or > > > > subtype type_1 is Integer; > > subtype type_2 is Integer; > > > > type_1_instance : type_1; > > type_2_instance : type_2; > > type_1_instance_2 : type_1; > > > > type_1_instance := 1; > > type_2_instance := 2; > > type_1_instance_2 := type_1_instance + > > type_2_instance; > > > > The addition operator is taking two disparate but > > related types and adding them. This is fine, > > up-casting is a normal thing. However, when the > result > > is returned it is not (should not be?) an instance > of > > the subtype. It seems that the compiler is > > down-casting automatically. This bothers me and it > > seams that is violates Ada's strong typing. What > am I > > missing here? > > Use type not subtype if you do not want the above > behavior. Read > below (taken from: > http://goanna.cs.rmit.edu.au/~dale/ada/aln/4_basic_types.htmli > ) > > Subtypes > > We can restrict the range of values a variable can > take by declaring a > subtype with a restricted range of values (this > corresponds to Pascal's > user defined types). Any attempt to place an > out-of-range value into a > variable of a subtype results in an exception > (program error). In this > way program errors can be discovered. The syntax for > a subtype > declaration is > > subtype Name is Base_Type; > subtype Name is Base_Type range lowerbound . . > upperbound; > > Examples of declaring subtypes are given below. > > type Processors is (M68000, i8086, i80386, M68030, > Pentium, PowerPC); > subtype Old_Processors is Processors range > M68000..i8086; > subtype New_Processors is Processors range > Pentium..PowerPC; > > subtype Data is Integer; > subtype Age is Data range 0 . . 140; > subtype Temperatures is Float range -50.0 .. 200.0; > subtype Upper_Chars is Character range 'A' .. 'Z'; > > Subtypes are compatable with their base types . They > can be placed in > the same place as any variable of the base type can. > Also variables of > different subtypes that are derived from the same > base type are > compatable. > > My_Age : Age; > Height : Integer; > > Height := My_Age; -- silly, but never causes a > problem. > > My_Age := Height; -- will cause a problem if > height's > -- value is outside the range of > -- my_age (0..140), but still > -- compilable. > > > Preben > -- > Please, stop bombing civilians in Afghanistan. One > cannot write off > killing innocent children and other civilians as > "collateral damage". > A civilian is a civilian whether he or she is > American or from another > country in the world. > http://web.amnesty.org/11september.htm > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 4:44 ` A question and a request Eric Merritt 2001-11-07 11:00 ` Preben Randhol @ 2001-11-07 13:58 ` James Rogers 2001-11-07 16:32 ` Jeffrey Carter 2001-11-09 23:32 ` Matthew Heaney 3 siblings, 0 replies; 9+ messages in thread From: James Rogers @ 2001-11-07 13:58 UTC (permalink / raw) To: comp.lang.ada Eric, I see you have already gotten an explanation of how subtypes work. I am willing to act as a quasi-mentor for your Ada st;udies. I have been studying and programming in Ada since 1994. That does not make me the most qualified from comp.lang.ada, but I do think I can help. I have been programming in C since 1981. I also know Java, and have some familiarity with Perl. Jim Rogers Colorado Springs, Colorado USA Eric Merritt wrote: > > > My request is a bit simpler, is there any one out > there willing to serve as kind of a quasi-mentor. > Basically look at some simple code occasionally and > tell me when I am getting bad habits. I have found > when learning other languages without experienced > input that I am able to pick up the language in a few > weeks or months and then it takes me a couple of years > to realize I have bad habits and attempt to rectify > them. This shouldn't be too time consuming for the > volunteer. I have been programming in other languages > professionally (C/C++, Java, Perl and Python) and I > have a good understanding of the theory. I just need > someone to occasionally look and say "hey this is > stupid, in Ada do it this way" or "In Ada its better > to take this approach". I could post stuff to the list > but this seams to be poor etiquette. > > In any case, if I get an answer to my first question I > will be happy. Thanks > > __________________________________________________ > Do You Yahoo!? > Find a job, post your resume. > http://careers.yahoo.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 4:44 ` A question and a request Eric Merritt 2001-11-07 11:00 ` Preben Randhol 2001-11-07 13:58 ` James Rogers @ 2001-11-07 16:32 ` Jeffrey Carter 2001-11-09 23:32 ` Matthew Heaney 3 siblings, 0 replies; 9+ messages in thread From: Jeffrey Carter @ 2001-11-07 16:32 UTC (permalink / raw) Although you have received some responses, I think the simple answer to your problem is that your example has only one type in it: Integer. Subtypes do not create new types and do not create new operations. The "+" in your example is defined as function "+" (Left : Integer; Right : Integer) return Integer; -- Jeffrey Carter ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: A question and a request 2001-11-07 4:44 ` A question and a request Eric Merritt ` (2 preceding siblings ...) 2001-11-07 16:32 ` Jeffrey Carter @ 2001-11-09 23:32 ` Matthew Heaney 3 siblings, 0 replies; 9+ messages in thread From: Matthew Heaney @ 2001-11-09 23:32 UTC (permalink / raw) "Eric Merritt" <cyberlync@yahoo.com> wrote in message news:mailman.1005116423.21054.comp.lang.ada@ada.eu.org... > The addition operator is taking two disparate but > related types and adding them. You have to be careful about how you use the terms "type" and "subtype". The (sub)types you defined simply name subsets of a common type. > This is fine, > up-casting is a normal thing. However, when the result > is returned it is not (should not be?) an instance of > the subtype. The addition operator looks like this: function "+" (L, R : Integer'Base) return Integer'Base; Only a "type" has operations. Subtypes merely name a range of values within the scalar type. Your addition operator is returning a value in the set (whose values are named by the type). Then there is an assignment, which checks to make sure the value (on the RHS) lies in the range of the subtype (of the object on the LHS). > It seems that the compiler is > down-casting automatically. This bothers me and it > seams that is violates Ada's strong typing. What am I > missing here? No, it does not, because there is only one type: the type whose first named subtype is Integer. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2001-11-09 23:32 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <3BE93E12.7BB33908@worldnet.att.net> 2001-11-07 17:38 ` A question and a request Eric Merritt 2001-11-06 23:52 List Container Straw Man Nick Roberts 2001-11-07 4:44 ` A question and a request Eric Merritt 2001-11-07 11:00 ` Preben Randhol 2001-11-07 12:54 ` David C. Hoos, Sr. 2001-11-08 2:35 ` dale 2001-11-07 13:24 ` Eric Merritt 2001-11-07 13:58 ` James Rogers 2001-11-07 16:32 ` Jeffrey Carter 2001-11-09 23:32 ` Matthew Heaney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox