* Elemantary Ada question @ 2000-11-28 0:00 Reinert Korsnes 2000-11-28 0:00 ` Lutz Donnerhacke ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Reinert Korsnes @ 2000-11-28 0:00 UTC (permalink / raw) Hi, Given the following simple test program: with Text_IO; use Text_IO; procedure Atest1 is type E1 is (a, b, c); package E1_Io is new Text_IO.Enumeration_Io (E1); use E1_Io; A : Float; begin Put(E1'First); end Atest1; Can anybody explain me why "A : Float" conflicts with the declaration: "type E1 is (a, b, c);" ? reinert -- Norwegian Polar Institute Polar Environment Center N-9296 Tromso Norway Fax: +47 77750501 http://geophys.npolar.no/~reinert/personal.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 Elemantary Ada question Reinert Korsnes @ 2000-11-28 0:00 ` Lutz Donnerhacke 2000-11-28 0:00 ` Reinert Korsnes 2000-11-28 0:00 ` Robert A Duff 2000-11-28 0:00 ` Scott Ingram 2 siblings, 1 reply; 8+ messages in thread From: Lutz Donnerhacke @ 2000-11-28 0:00 UTC (permalink / raw) * Reinert Korsnes wrote: >Can anybody explain me why "A : Float" conflicts >with the declaration: "type E1 is (a, b, c);" ? Ada is case-in-sensitive. -- http://www.tm.oneiros.de/calendar/2001/index.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 ` Lutz Donnerhacke @ 2000-11-28 0:00 ` Reinert Korsnes 2000-11-28 0:00 ` Mats Weber ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Reinert Korsnes @ 2000-11-28 0:00 UTC (permalink / raw) In article <slrn927ai8.tq.lutz@taranis.iks-jena.de>, lutz@iks-jena.de (Lutz Donnerhacke) writes: >* Reinert Korsnes wrote: >>Can anybody explain me why "A : Float" conflicts >>with the declaration: "type E1 is (a, b, c);" ? > >Ada is case-in-sensitive. Ok, let A be a possible value of a variable of type E1 (let say "type E1 is (A, B, C)"). And A is a variable name. Where is the conflict ? -----------------the test program is as follows (repeating): with Text_IO; use Text_IO; procedure Atest1 is type E1 is (a, b, c); package E1_Io is new Text_IO.Enumeration_Io (E1); use E1_Io; A : Float; begin Put(E1'First); end Atest1; reinert > >-- > http://www.tm.oneiros.de/calendar/2001/index.html -- Norwegian Polar Institute Polar Environment Center N-9296 Tromso Norway Fax: +47 77750501 http://geophys.npolar.no/~reinert/personal.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 ` Reinert Korsnes @ 2000-11-28 0:00 ` Mats Weber 2000-11-28 0:00 ` Ted Dennison 2000-11-28 0:00 ` Lutz Donnerhacke 2 siblings, 0 replies; 8+ messages in thread From: Mats Weber @ 2000-11-28 0:00 UTC (permalink / raw) If you want to declare an identifier twice in the same declarative region, _both_ declarations must be either an enumeration literal, a function or a procedure (i.e. overloadable entities). If one of them is something else, then it's illegal. The actual rule is a little more complicated than that, you can have a look at LRM 8.3. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 ` Reinert Korsnes 2000-11-28 0:00 ` Mats Weber @ 2000-11-28 0:00 ` Ted Dennison 2000-11-28 0:00 ` Lutz Donnerhacke 2 siblings, 0 replies; 8+ messages in thread From: Ted Dennison @ 2000-11-28 0:00 UTC (permalink / raw) In article <900bgt$i6t$1@news.uit.no>, Reinert.Korsnes@npolar.no wrote: > In article <slrn927ai8.tq.lutz@taranis.iks-jena.de>, > lutz@iks-jena.de (Lutz Donnerhacke) writes: > >* Reinert Korsnes wrote: > >>Can anybody explain me why "A : Float" conflicts > >>with the declaration: "type E1 is (a, b, c);" ? > > > >Ada is case-in-sensitive. > > Ok, let A be a possible value of a variable of type E1 > (let say "type E1 is (A, B, C)"). > And A is a variable name. > > Where is the conflict ? If you are saying that in many cases where you would write "A", its type could theoreticly be figured out by the context of the statement, then you are right. However, its pretty easy to construct examples where it couldn't. What matters here to you isn't what's theoreticly possible for a compiler to do, but what Ada allows you to do. In Ada, reusing an Identifier for multiple objects can cause one of two basic situations; hiding or overloading (in truth, there's a few more, but we'll ignore those situations for now). "Overloading" is where both objects exist simultaniously and the compiler will figure out which was intended from context at compile time. Overloading is only allowed for subprograms (functions and procedures) with different parameter profiles, and enumeration literals. Any other time an indentifier is reused, it should cause hiding; the later declaration "hides" the earlier one for the entirety of its scope. This implies that they can't be declared at the same scope (otherwise, there's no point to the earlier declaration). Now in your case, then enumeration literal "A" could be overloaded, if your other "A" were a subprogram or enumeration literal. But since your other "A" is just a variable declation, this must be a hiding situation. But it can't be a hiding situation because they are both declared at the same scope. Therefore its illegal. Now this was a very informal (read: wrong in many details) treatment of the subject. If you want to go over the actual legaleese rules involved, see 8.3 of the LRM (available online at http://www.adapower.com/rm95/arm95_128.html#SEC128 ) -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/ Before you buy. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 ` Reinert Korsnes 2000-11-28 0:00 ` Mats Weber 2000-11-28 0:00 ` Ted Dennison @ 2000-11-28 0:00 ` Lutz Donnerhacke 2 siblings, 0 replies; 8+ messages in thread From: Lutz Donnerhacke @ 2000-11-28 0:00 UTC (permalink / raw) * Reinert Korsnes wrote: >In article <slrn927ai8.tq.lutz@taranis.iks-jena.de>, > lutz@iks-jena.de (Lutz Donnerhacke) writes: >>* Reinert Korsnes wrote: >>>Can anybody explain me why "A : Float" conflicts >>>with the declaration: "type E1 is (a, b, c);" ? >> >>Ada is case-in-sensitive. > >Ok, let A be a possible value of a variable of type E1 >(let say "type E1 is (A, B, C)"). >And A is a variable name. > >Where is the conflict ? There are two identical terms in the same namespace. What should 'if A = A then ...' mean? How to determine the Float value and the enumeration constant? type E1 is (A, B, C); can be assumed as type E1 is range 1 .. 3; A : constant E1 := 1; B : constant E1 := 2; C : constant E1 := 3; -- http://www.tm.oneiros.de/calendar/2001/index.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 Elemantary Ada question Reinert Korsnes 2000-11-28 0:00 ` Lutz Donnerhacke @ 2000-11-28 0:00 ` Robert A Duff 2000-11-28 0:00 ` Scott Ingram 2 siblings, 0 replies; 8+ messages in thread From: Robert A Duff @ 2000-11-28 0:00 UTC (permalink / raw) reinert@ola.npolar.no (Reinert Korsnes) writes: > Can anybody explain me why "A : Float" conflicts > with the declaration: "type E1 is (a, b, c);" ? Enumeration literals are overloadable, but variables are not overloadable. You are not allowed to have a non-overloadable A if there is some other A in the same scope (even if the other one is overloadable). The exact rules are in chapter 8 of the RM. It says that two declarations with the same name are "homographs" if one or both are non-overloadable. Also, if both are overloadable, and have the same parameter and result types (where the enumeration literal A is like a parameterless function returning type E1). It is illegal to have two homographs in the same "declarative region". Or perhaps you are asking why was the language defined that way. Well, variable names could be overloadable, and the language rules would work just fine. The above would be legal, and things like X: E1 := A; would resolve to the right A. Things like "if A = A..." would be ambiguous, and therefore illegal. - Bob ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elemantary Ada question 2000-11-28 0:00 Elemantary Ada question Reinert Korsnes 2000-11-28 0:00 ` Lutz Donnerhacke 2000-11-28 0:00 ` Robert A Duff @ 2000-11-28 0:00 ` Scott Ingram 2 siblings, 0 replies; 8+ messages in thread From: Scott Ingram @ 2000-11-28 0:00 UTC (permalink / raw) Reinert Korsnes wrote: > > Can anybody explain me why "A : Float" conflicts > with the declaration: "type E1 is (a, b, c);" ? > > reinert > Because identifiers in Ada are case insensitive, so 'a : Float' is a redeclaration of an already declared enumeration type ('type E1 is (A, B, C);') -- Scott Ingram Vice-Chair, Baltimore SIGAda Sonar Processing and Analysis Laboratory Johns Hopkins University Applied Physics Laboratory ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2000-11-28 0:00 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2000-11-28 0:00 Elemantary Ada question Reinert Korsnes 2000-11-28 0:00 ` Lutz Donnerhacke 2000-11-28 0:00 ` Reinert Korsnes 2000-11-28 0:00 ` Mats Weber 2000-11-28 0:00 ` Ted Dennison 2000-11-28 0:00 ` Lutz Donnerhacke 2000-11-28 0:00 ` Robert A Duff 2000-11-28 0:00 ` Scott Ingram
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox