* Package Instances??? @ 2002-02-13 21:02 Yates 2002-02-13 21:12 ` Larry Kilgallen ` (4 more replies) 0 siblings, 5 replies; 29+ messages in thread From: Yates @ 2002-02-13 21:02 UTC (permalink / raw) I am new to Ada. I'd like to know if it is possible to create multiple instances of a package. For example, if I have a package 'My_Package', can I do something like: p1 : My_Package := new My_Package p2 : My_Package := new My_Package ..... I tried this and didn't work. Is there other ways to do it? Thanks Yates ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:02 Package Instances??? Yates @ 2002-02-13 21:12 ` Larry Kilgallen 2002-02-13 21:21 ` chris.danx ` (3 subsequent siblings) 4 siblings, 0 replies; 29+ messages in thread From: Larry Kilgallen @ 2002-02-13 21:12 UTC (permalink / raw) In article <721b6d80.0202131302.1ccce2ed@posting.google.com>, yates_1900@yahoo.com (Yates) writes: > I am new to Ada. I'd like to know if it is possible to create multiple > instances of a package. For example, if I have a package 'My_Package', can > I do something like: > > p1 : My_Package := new My_Package > p2 : My_Package := new My_Package > ..... > > I tried this and didn't work. Is there other ways to do it? You just said that. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:02 Package Instances??? Yates 2002-02-13 21:12 ` Larry Kilgallen @ 2002-02-13 21:21 ` chris.danx 2002-02-13 21:46 ` Marin David Condic ` (2 subsequent siblings) 4 siblings, 0 replies; 29+ messages in thread From: chris.danx @ 2002-02-13 21:21 UTC (permalink / raw) "Yates" <yates_1900@yahoo.com> wrote in message news:721b6d80.0202131302.1ccce2ed@posting.google.com... > I am new to Ada. I'd like to know if it is possible to create multiple > instances of a package. For example, if I have a package 'My_Package', can > I do something like: > > p1 : My_Package := new My_Package > p2 : My_Package := new My_Package > ..... > > I tried this and didn't work. Is there other ways to do it? Why would you need to for ordinary work? All the public types and subroutines will be available to you when you with it the first time, so you only need to 'with' it in a package once to use it in that package. In the case of generics you can instantiate multiple packages for different types (*maybe* even the same ones over again), but if your just starting you probably don't need generics. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:02 Package Instances??? Yates 2002-02-13 21:12 ` Larry Kilgallen 2002-02-13 21:21 ` chris.danx @ 2002-02-13 21:46 ` Marin David Condic 2002-02-14 17:59 ` Hyman Rosen 2002-02-13 21:50 ` Eric Merritt 2002-02-14 15:08 ` Yates 4 siblings, 1 reply; 29+ messages in thread From: Marin David Condic @ 2002-02-13 21:46 UTC (permalink / raw) Sounds like you're trying to treat a package as if it was a C++ class and you're trying to create a new instance of it because it presumably holds a set of variables you want to duplicate? First, as you discovered, you can't do that. Second, it isn't really the right idiom for Ada. The way to do it would be to have a record type declared in the package that holds all your variables. Then you create objects of the record type & use the operations contained in the package on the individual objects of that type. Something like this: package My_Package is type My_Rec is record A : Integer ; B : Integer ; C : Integer ; end record ; function Some_Operation (Rec : My_Rec) return Integer ; end My_Package ; -- Then in the unit that uses it... X : My_Package.My_Rec ; -- One instance of the A, B, C variables Y : My_Package.My_Rec ; -- A whole different instance of them. ....... -- Operates on X.A, X.B, X.C Some_Int := My_Package.Some_Operation (X) ; ....... -- Operates on Y.A, Y.B, Y.C Another_Int := My_Package.Some_Operation (Y) ; ....... If that's what you were trying to accomplish, I hope this clarifies. If it was something else, see if you can explain what you are trying to do and maybe we can help you find The Ada Way of doing it. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Yates" <yates_1900@yahoo.com> wrote in message news:721b6d80.0202131302.1ccce2ed@posting.google.com... > I am new to Ada. I'd like to know if it is possible to create multiple > instances of a package. For example, if I have a package 'My_Package', can > I do something like: > > p1 : My_Package := new My_Package > p2 : My_Package := new My_Package > ..... > > I tried this and didn't work. Is there other ways to do it? > > Thanks > > Yates ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:46 ` Marin David Condic @ 2002-02-14 17:59 ` Hyman Rosen 2002-02-15 13:11 ` Marc A. Criley 2002-02-15 19:20 ` Simon Wright 0 siblings, 2 replies; 29+ messages in thread From: Hyman Rosen @ 2002-02-14 17:59 UTC (permalink / raw) Marin David Condic wrote: > Sounds like you're trying to treat a package as if it was a C++ class and > you're trying to create a new instance of it because it presumably holds a > set of variables you want to duplicate? First, as you discovered, you can't > do that. Second, it isn't really the right idiom for Ada. Wouldn't it work by just making the package generic? ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-14 17:59 ` Hyman Rosen @ 2002-02-15 13:11 ` Marc A. Criley 2002-02-15 19:20 ` Simon Wright 1 sibling, 0 replies; 29+ messages in thread From: Marc A. Criley @ 2002-02-15 13:11 UTC (permalink / raw) Hyman Rosen wrote: > > Marin David Condic wrote: > > Sounds like you're trying to treat a package as if it was a C++ class and > > you're trying to create a new instance of it because it presumably holds a > > set of variables you want to duplicate? First, as you discovered, you can't > > do that. Second, it isn't really the right idiom for Ada. > > Wouldn't it work by just making the package generic? I got a clear impression from the original posting that he was thinking that packages were very much like classes, which is what his example strongly suggested. So I think the postings about generics were answering a question that wasn't being asked :-) Marc A. Criley Consultant Quadrus Corporation www.quadruscorp.com ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-14 17:59 ` Hyman Rosen 2002-02-15 13:11 ` Marc A. Criley @ 2002-02-15 19:20 ` Simon Wright 2002-02-19 14:08 ` Marin David Condic 1 sibling, 1 reply; 29+ messages in thread From: Simon Wright @ 2002-02-15 19:20 UTC (permalink / raw) Hyman Rosen <hyrosen@mail.com> writes: > Marin David Condic wrote: > > Sounds like you're trying to treat a package as if it was a C++ class and > > you're trying to create a new instance of it because it presumably holds a > > set of variables you want to duplicate? First, as you discovered, you can't > > do that. Second, it isn't really the right idiom for Ada. > > Wouldn't it work by just making the package generic? But different instantiations would be different "classes". I guess that depends on what the generic actually says. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-15 19:20 ` Simon Wright @ 2002-02-19 14:08 ` Marin David Condic 2002-02-20 1:37 ` Matthew Heaney 0 siblings, 1 reply; 29+ messages in thread From: Marin David Condic @ 2002-02-19 14:08 UTC (permalink / raw) In the simplest case where the generic package had no generic parameters and only a collection of data objects & subprograms, it would look very similar to a C++ "class" in many respects. The important part being that it would only *look* like a C++ class. Semantically the whole analogy starts to fall apart once you start picking at the loose threads. Obviously, as you observe, once you start changing what the generic actually says, the distinction between a generic package and a "class" starts becoming more apparent. In general, I'd think it would be wise not to try to use a generic package to represent a "class" in the way it appears to have been intended. Its just the wrong idiom in Ada to do what a C++ class does. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Simon Wright" <simon@pushface.org> wrote in message news:x7v8z9u7dsk.fsf@smaug.pushface.org... > > But different instantiations would be different "classes". I guess > that depends on what the generic actually says. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-19 14:08 ` Marin David Condic @ 2002-02-20 1:37 ` Matthew Heaney 2002-02-20 16:56 ` Marin David Condic 2002-02-20 19:16 ` Hyman Rosen 0 siblings, 2 replies; 29+ messages in thread From: Matthew Heaney @ 2002-02-20 1:37 UTC (permalink / raw) "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org> wrote in message news:a4tm89$ajg$1@nh.pace.co.uk... > Obviously, as you observe, once you start changing what the generic actually > says, the distinction between a generic package and a "class" starts > becoming more apparent. In general, I'd think it would be wise not to try to > use a generic package to represent a "class" in the way it appears to have > been intended. Its just the wrong idiom in Ada to do what a C++ class does. Yes. An Ada package is analogous to a C++ namespace, not a class. Actually, there's a straight-forward conversion from C++ to Ada: namespace N { class C { public: //... private: //... }; } //end namespace N package P is type T is private; --... private type T is record ...; --... end P; ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 1:37 ` Matthew Heaney @ 2002-02-20 16:56 ` Marin David Condic 2002-02-21 15:33 ` Matthew Heaney 2002-02-20 19:16 ` Hyman Rosen 1 sibling, 1 reply; 29+ messages in thread From: Marin David Condic @ 2002-02-20 16:56 UTC (permalink / raw) Excellent illustration. Lat time I checked though, there were several C++ compilers not supporting namespaces though - notably MSVC++, IIRC. Not involved with it at the moment, so maybe its changed. Are more C++ compilers supporting it? (It sure does overcome some of the big limitations I found with C++...) MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Matthew Heaney" <mheaney@on2.com> wrote in message news:u75v5l119fc64c@corp.supernews.com... > > Yes. An Ada package is analogous to a C++ namespace, not a class. > > Actually, there's a straight-forward conversion from C++ to Ada: > > namespace N > { > class C > { > public: > //... > private: > //... > }; > } //end namespace N > > package P is > type T is private; > --... > private > type T is record ...; > --... > end P; > ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 16:56 ` Marin David Condic @ 2002-02-21 15:33 ` Matthew Heaney 0 siblings, 0 replies; 29+ messages in thread From: Matthew Heaney @ 2002-02-21 15:33 UTC (permalink / raw) "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org> wrote in message news:a50kfe$n39$1@nh.pace.co.uk... > Excellent illustration. Lat time I checked though, there were several C++ > compilers not supporting namespaces though - notably MSVC++, IIRC. Not > involved with it at the moment, so maybe its changed. Are more C++ compilers > supporting it? (It sure does overcome some of the big limitations I found > with C++...) Visual C++ v6 works fine, as does g++ v2.96. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 1:37 ` Matthew Heaney 2002-02-20 16:56 ` Marin David Condic @ 2002-02-20 19:16 ` Hyman Rosen 2002-02-20 22:31 ` Pat Rogers 2002-02-20 23:44 ` Matthew Heaney 1 sibling, 2 replies; 29+ messages in thread From: Hyman Rosen @ 2002-02-20 19:16 UTC (permalink / raw) Matthew Heaney wrote: > Yes. An Ada package is analogous to a C++ namespace, not a class. Except that in Ada, a package can be used as a parameter for a generic instantiation, but in C++ a namespace cannot be used as a template argument. Given that C++ classes can have arbitrary things defined in them (types, static functions, constants, etc.) considering them as an analogue of Ada packages is not wrong. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 19:16 ` Hyman Rosen @ 2002-02-20 22:31 ` Pat Rogers 2002-02-20 23:44 ` Matthew Heaney 1 sibling, 0 replies; 29+ messages in thread From: Pat Rogers @ 2002-02-20 22:31 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C73F5F6.7050704@mail.com... > Matthew Heaney wrote: > > Yes. An Ada package is analogous to a C++ namespace, not a class. > > Except that in Ada, a package can be used as a parameter for a > generic instantiation, but in C++ a namespace cannot be used as > a template argument. Given that C++ classes can have arbitrary > things defined in them (types, static functions, constants, etc.) > considering them as an analogue of Ada packages is not wrong. Yes, I agree with that sentiment, but I don't agree that one can make the analogies in isolation from other language elements. I would express it thusly: a C++ class declared is analogous to a tagged type declared within a package visible part. The package, the type, and the corresponding primitive operations work together to form an abstraction. This atomicity is illustrated, for example, by the fact that subprograms are not primitive operations of the type unless they are declared in the same package as the tagged type declaration itself (in addition to the other requirement, namely, that they mention the type in their parameter and (for functions) result type profile). Subprograms that meet the second requirement but not the first are not primitive operations of the type and thus are not inherited and are not dynamically dispatched. A package not exporting a tagged type with primitive operations could correspond to a C++ namespace. What's missing is that, like Java's packages, C++ namespaces can be extended dynamically -- they can be "re-opened". An Ada package is a module, with a definite end. But then there are subsystems... You might be interested in the Ada generated from UML by a product called "UML Studio" (www.pragsoft.com). It uses the specified namespace of the UML class, if present, as the package name, and the UML class name for the tagged type name within that package. If the namespace is not specified, it uses the class name as the package name and "Object" for the tagged type name. --- Patrick Rogers Consulting and Training in: http://www.classwide.com Real-Time/OO Languages progers@classwide.com Hard Deadline Schedulability Analysis (281)648-3165 Software Fault Tolerance ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 19:16 ` Hyman Rosen 2002-02-20 22:31 ` Pat Rogers @ 2002-02-20 23:44 ` Matthew Heaney 2002-02-21 5:35 ` Hyman Rosen 1 sibling, 1 reply; 29+ messages in thread From: Matthew Heaney @ 2002-02-20 23:44 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C73F5F6.7050704@mail.com... > Given that C++ classes can have arbitrary > things defined in them (types, static functions, constants, etc.) > considering them as an analogue of Ada packages is not wrong. But it is wrong if your purpose is to implement a type, so that you can declare objects, which you can pass to subprograms, etc. The fact that in C++ you can declare things inside the class is irrelevent. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-20 23:44 ` Matthew Heaney @ 2002-02-21 5:35 ` Hyman Rosen 2002-02-21 14:05 ` Marin David Condic 2002-02-21 15:30 ` Matthew Heaney 0 siblings, 2 replies; 29+ messages in thread From: Hyman Rosen @ 2002-02-21 5:35 UTC (permalink / raw) Matthew Heaney wrote: > "Hyman Rosen" <hyrosen@mail.com> wrote > >>Given that C++ classes can have arbitrary >>things defined in them (types, static functions, constants, etc.) >>considering them as an analogue of Ada packages is not wrong. > > But it is wrong if your purpose is to implement a type, so that you can > declare objects, which you can pass to subprograms, etc. The fact that in > C++ you can declare things inside the class is irrelevent. But my purpose isn't to implement a type, it's to find a C++ analogue for Ada packages. C++ namespaces are useless for anything except what the name implies, namely establishing a namespace. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-21 5:35 ` Hyman Rosen @ 2002-02-21 14:05 ` Marin David Condic 2002-02-22 16:49 ` Hyman Rosen 2002-02-21 15:30 ` Matthew Heaney 1 sibling, 1 reply; 29+ messages in thread From: Marin David Condic @ 2002-02-21 14:05 UTC (permalink / raw) But why fight it? When programming in C++, the fundamental idiom is the class - maybe with a namespace around it to isolate the identifiers & produce better encapsulation. When programming in Ada, the fundamental idiom is the package - which gives you encapsulation and lots of other cool stuff - but isn't an "object" or a "type" so it can't really do what a C++ class does. It needs to contain a tagged type to complete the picture. I don't think that C++ really has an analog for what Ada does with a package - at least nothing that provides anything resembling a mirror image. It has things that will give you some of the features of a package - but because it carries so much legacy from C the whole concept of what Ada does with a package is rather foreign and it would be difficult to add something to C++ that would create a "package" and still maintaining upward compatibility. I think Ada's packages are a big advantage and a good reason to do things in Ada instead of C++ (or C, for that matter). The encapsulation, separation of interface and implementation and information hiding alone is worth it. You can get something similar out of C++, sort of, if you work at it, but it always seemed to me to be something you had to cobble together out of spare parts in a junk drawer rather than something that was inherently engineered into the language. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C7487D6.5060603@mail.com... > > But my purpose isn't to implement a type, it's to find a C++ analogue > for Ada packages. C++ namespaces are useless for anything except what > the name implies, namely establishing a namespace. > ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-21 14:05 ` Marin David Condic @ 2002-02-22 16:49 ` Hyman Rosen 2002-02-22 17:22 ` Marin David Condic 2002-02-22 18:10 ` Matthew Heaney 0 siblings, 2 replies; 29+ messages in thread From: Hyman Rosen @ 2002-02-22 16:49 UTC (permalink / raw) Depending on how one builds it, a C++ class or class template can fulfill the role of an Ada package, record, or tagged type. That's just the way it is. To examine equivalent capabilities in the two languages, you *must* use a C++ class to emulate an Ada package, otherwise there will be all sorts of things that you can do in Ada that won't be possible in C++. It is simplistic and wrong to argue that a C++ class is just like an Ada tagged type. That just is not how classes are used in modern C++. It may appear to be cobbled together because of the C heritage, and because a lot of the idioms were discovered late in the game, but the non-tagged-type usages are at least as important and useful as the OO stuff. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 16:49 ` Hyman Rosen @ 2002-02-22 17:22 ` Marin David Condic 2002-02-24 7:39 ` Hyman Rosen 2002-02-22 18:10 ` Matthew Heaney 1 sibling, 1 reply; 29+ messages in thread From: Marin David Condic @ 2002-02-22 17:22 UTC (permalink / raw) O.K. But please take a moment to recall that I never said that a C++ class was "just like" an Ada tagged type. I've been stating consistently that you can't presume that a feature of Language X is going to have an exact parallel in Language Y. I wouldn't make the claim that a C++ class and an Ada tagged type are plug compatible. They both have their own semantics that aren't going to mirror-image each other and attempting to force them to be the same is a mistake. What I *am* claiming is that if you want to do something similar to a C++ class in Ada, that attempting to do it with a package is going to lead to disappointing results. Using a package in conjunction with a tagged type is the correct idiom in Ada for representing a "class" (general concept - not C++ class). When comparing C++ and Ada, it really is important to remember that you can get the same end results from either language, but you can't necessarily get those results in an identical manner. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C7676AF.9020404@mail.com... > > It is simplistic and wrong to argue that a C++ class is just > like an Ada tagged type. That just is not how classes are used > in modern C++. It may appear to be cobbled together because of > the C heritage, and because a lot of the idioms were discovered > late in the game, but the non-tagged-type usages are at least > as important and useful as the OO stuff. > ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 17:22 ` Marin David Condic @ 2002-02-24 7:39 ` Hyman Rosen 2002-02-25 15:38 ` Matthew Heaney 0 siblings, 1 reply; 29+ messages in thread From: Hyman Rosen @ 2002-02-24 7:39 UTC (permalink / raw) Marin David Condic wrote: > What I *am* claiming is that if you want to do something similar to a C++ > class in Ada, that attempting to do it with a package is going to lead to > disappointing results. Using a package in conjunction with a tagged type is > the correct idiom in Ada for representing a "class" (general concept - not > C++ class). Yes, that is exactly what I believe! I think it's Matthew Heaney who is arguing otherwise. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-24 7:39 ` Hyman Rosen @ 2002-02-25 15:38 ` Matthew Heaney 0 siblings, 0 replies; 29+ messages in thread From: Matthew Heaney @ 2002-02-25 15:38 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C78998A.10006@mail.com... > Yes, that is exactly what I believe! I think it's Matthew Heaney > who is arguing otherwise. Well, if you say "implement it as a type in Ada," that also implies the use of a package, because you can't declare library-level types, only packages. Therefore I didn't think it was necessary to call out the use of a package explicitly. But if only say "implement it as a package in Ada," then that is ambiguous, because someone (like me) will think you mean to use only a package, and not an abstract data type too. Perhaps the locution "implement as an abstract data type declared in a package" is necessary to militate against any misunderstanding. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 16:49 ` Hyman Rosen 2002-02-22 17:22 ` Marin David Condic @ 2002-02-22 18:10 ` Matthew Heaney 2002-02-22 20:55 ` Hyman Rosen 1 sibling, 1 reply; 29+ messages in thread From: Matthew Heaney @ 2002-02-22 18:10 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C7676AF.9020404@mail.com... > Depending on how one builds it, a C++ class or class template > can fulfill the role of an Ada package, record, or tagged type. We all agree it's not a perfect comparison, since a class in C++ has type semantics and module semantics, and in Ada they are orthogonal. > That's just the way it is. This is not a description of ontic reality, it is a description of your subjective experience. I suggest you study instrumentalism (Dewey) or pragmatic philosophy (James, Peirce). See also Ernst von Glasersfeld and Heinz von Foerster. Indeed, any book on general systems theory. > To examine equivalent capabilities in the two languages, you > *must* use a C++ class to emulate an Ada package, otherwise > there will be all sorts of things that you can do in Ada that > won't be possible in C++. Wrong. An Ada package is a C++ namespace. An Ada private type is a C++ class. The fact that genericity is attached to modules in Ada rather than to the type itself is irrelevant. > It is simplistic and wrong to argue that a C++ class is just > like an Ada tagged type. Well, if a C++ class has virtual methods, then it has a vtable, which exactly corresponds to an Ada tagged type. A C++ class sans virtual methods has no vtable, and hence is equivalent to a nontagged Ada type. A C++ class is an Ada type. The fact that a C++ class has module semantics too is irrelevant. > That just is not how classes are used > in modern C++. It may appear to be cobbled together because of > the C heritage, and because a lot of the idioms were discovered > late in the game, but the non-tagged-type usages are at least > as important and useful as the OO stuff. On that we most certainly agree. The Ada community has been saying this from the very beginning, but certain pedantic computer scientists (and lots of obsequious programmers who followed the party line) weren't convinced. Thankfully Stroustrup has tempered this unbridled enthusiasm for all things "pure object-oriented" by demonstrating the benefits of non-extensible types and static method binding. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 18:10 ` Matthew Heaney @ 2002-02-22 20:55 ` Hyman Rosen 2002-02-22 21:37 ` Matthew Heaney 0 siblings, 1 reply; 29+ messages in thread From: Hyman Rosen @ 2002-02-22 20:55 UTC (permalink / raw) Matthew Heaney wrote: > "Hyman Rosen" <hyrosen@mail.com> wrote >>Depending on how one builds it, a C++ class or class template >>can fulfill the role of an Ada package, record, or tagged type. > > We all agree it's not a perfect comparison, since a class in C++ has type > semantics and module semantics, and in Ada they are orthogonal. Of course it's not a perfect comparison! We are talking about two different and largely independent programming languages. > Wrong. An Ada package is a C++ namespace. An Ada private type is a C++ > class. The fact that genericity is attached to modules in Ada rather than > to the type itself is irrelevant. An Ada package is not a C++ namespace, since it's written in Ada, not in C++. The issue we're dealing with is how to best represent the construct of one programming language in another. When one construct has many aspects to it, it is likely that such cross-language representation will depend on which aspect is pre-eminent. In Ada, a package may be passed as a parameter to a generic instantiation. A package body may have a begin-end section which runs when the package is elaborated. You mat have a generic package. The proper way to represent these abilities in C++ is as a class or class template, not a namespace. You may have some Ada packages which don't make use of any of these features, and those can be represented as namespaces, but that is not the case in general. > Well, if a C++ class has virtual methods, then it has a vtable, which > exactly corresponds to an Ada tagged type. A C++ class sans virtual methods > has no vtable, and hence is equivalent to a nontagged Ada type. An Ada tagged type is best represented as a C++ class with virtual methods. An Ada untagged record type is best represented as a C++ class without virtual methods. Notice that the direction here in both cases is how to represent an Ada construct in C++. Your second statement is completely false, however, because a C++ class may contain type definitions, constant definitions, and non-member functions, none of which are present in an untagged Ada type, but which *are* present in an Ada package. > A C++ class is an Ada type. The fact that a C++ class has module > semantics too is irrelevant. You may assert that all you like, but that will not make it true. Here's a C++ class: class c { typedef int t; enum { v = 3 }; }; What is the corresponding Ada type? > Thankfully Stroustrup has tempered this unbridled enthusiasm for all things > "pure object-oriented" by demonstrating the benefits of non-extensible types > and static method binding. Actually, all classes in C++ are extensible, but whatever. Anyway, the exciting C++ stuff these days is in template metaprogramming, which is pretty much inexpressible in Ada. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 20:55 ` Hyman Rosen @ 2002-02-22 21:37 ` Matthew Heaney 2002-02-24 7:36 ` Hyman Rosen 0 siblings, 1 reply; 29+ messages in thread From: Matthew Heaney @ 2002-02-22 21:37 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C76B04C.7050108@mail.com... > Here's a C++ class: class c { typedef int t; enum { v = 3 }; }; > What is the corresponding Ada type? package P is type C is private; private type C is null record; subtype T is Integer; V : constant := 3; end P; ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-22 21:37 ` Matthew Heaney @ 2002-02-24 7:36 ` Hyman Rosen 2002-02-25 15:27 ` Matthew Heaney 0 siblings, 1 reply; 29+ messages in thread From: Hyman Rosen @ 2002-02-24 7:36 UTC (permalink / raw) Matthew Heaney wrote: > "Hyman Rosen" <hyrosen@mail.com> wrote in message > news:3C76B04C.7050108@mail.com... > >>Here's a C++ class: class c { typedef int t; enum { v = 3 }; }; >>What is the corresponding Ada type? >> > > package P is > type C is private; > private > type C is null record; > subtype T is Integer; > V : constant := 3; > end P; Thus illustrating my point about the correspondence between Ada packages and C++ classes! ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-24 7:36 ` Hyman Rosen @ 2002-02-25 15:27 ` Matthew Heaney 0 siblings, 0 replies; 29+ messages in thread From: Matthew Heaney @ 2002-02-25 15:27 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C7898A4.2080102@mail.com... > Matthew Heaney wrote: > Thus illustrating my point about the correspondence between > Ada packages and C++ classes! Well, if that's how you'd translate it too, then it sounds like we're in violent agreement... ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-21 5:35 ` Hyman Rosen 2002-02-21 14:05 ` Marin David Condic @ 2002-02-21 15:30 ` Matthew Heaney 2002-02-21 18:05 ` Hyman Rosen 1 sibling, 1 reply; 29+ messages in thread From: Matthew Heaney @ 2002-02-21 15:30 UTC (permalink / raw) "Hyman Rosen" <hyrosen@mail.com> wrote in message news:3C7487D6.5060603@mail.com... > But my purpose isn't to implement a type, it's to find a C++ analogue > for Ada packages. C++ namespaces are useless for anything except what > the name implies, namely establishing a namespace. Well, if you don't need a type, then you really do want an Ada package. Clearly the C++ analogue is a namespace. package P is procedure Op; I : Integer; end P; namespace N { void f(); extern int i; } In Ada, you have P.Op and P.I, and in C++ you have N::f() and N::i. What's the problem? (Note that in C++ you could use a class, and declare f() and i as static members, but you said you didn't want a type.) ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-21 15:30 ` Matthew Heaney @ 2002-02-21 18:05 ` Hyman Rosen 0 siblings, 0 replies; 29+ messages in thread From: Hyman Rosen @ 2002-02-21 18:05 UTC (permalink / raw) Matthew Heaney wrote: > In Ada, you have P.Op and P.I, and in C++ you have N::f() and N::i. What's > the problem? In Ada, P can be passed as a package parameter to an instantiation of a generic. P can be made generic and then there could be multiple instantiations of it. P can have a body which does some initialization. No equivalent is possible in C++ if N is a namespace, only if N is a class or a class template. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:02 Package Instances??? Yates ` (2 preceding siblings ...) 2002-02-13 21:46 ` Marin David Condic @ 2002-02-13 21:50 ` Eric Merritt 2002-02-14 15:08 ` Yates 4 siblings, 0 replies; 29+ messages in thread From: Eric Merritt @ 2002-02-13 21:50 UTC (permalink / raw) Yates, You may actually be getting packages mixed up with classes as used in other languages. Packages are not so much a coherent whole as a collection of types and variables that you may use in your client program. So although you would not do p1 : My_Package := new My_Package; you would do something like p1: My_Package.My_Type : Create_New_My_Type; (If there was a function named Create_New_My_Type in the package). I would suggest you hit some of the excellent tutorials available to get you over this hump. --- Yates <yates_1900@yahoo.com> wrote: > I am new to Ada. I'd like to know if it is possible > to create multiple > instances of a package. For example, if I have a > package 'My_Package', can > I do something like: > > p1 : My_Package := new My_Package > p2 : My_Package := new My_Package > ..... > > I tried this and didn't work. Is there other ways to > do it? > > Thanks > > Yates > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada __________________________________________________ Do You Yahoo!? Send FREE Valentine eCards with Yahoo! Greetings! http://greetings.yahoo.com ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: Package Instances??? 2002-02-13 21:02 Package Instances??? Yates ` (3 preceding siblings ...) 2002-02-13 21:50 ` Eric Merritt @ 2002-02-14 15:08 ` Yates 4 siblings, 0 replies; 29+ messages in thread From: Yates @ 2002-02-14 15:08 UTC (permalink / raw) Thanks to all of you!!! Yates "Yates" <yates_1900@yahoo.com> wrote in message news:721b6d80.0202131302.1ccce2ed@posting.google.com... > I am new to Ada. I'd like to know if it is possible to create multiple > instances of a package. For example, if I have a package 'My_Package', can > I do something like: > > p1 : My_Package := new My_Package > p2 : My_Package := new My_Package > ..... > > I tried this and didn't work. Is there other ways to do it? > > Thanks > > Yates ^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2002-02-25 15:38 UTC | newest] Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-02-13 21:02 Package Instances??? Yates 2002-02-13 21:12 ` Larry Kilgallen 2002-02-13 21:21 ` chris.danx 2002-02-13 21:46 ` Marin David Condic 2002-02-14 17:59 ` Hyman Rosen 2002-02-15 13:11 ` Marc A. Criley 2002-02-15 19:20 ` Simon Wright 2002-02-19 14:08 ` Marin David Condic 2002-02-20 1:37 ` Matthew Heaney 2002-02-20 16:56 ` Marin David Condic 2002-02-21 15:33 ` Matthew Heaney 2002-02-20 19:16 ` Hyman Rosen 2002-02-20 22:31 ` Pat Rogers 2002-02-20 23:44 ` Matthew Heaney 2002-02-21 5:35 ` Hyman Rosen 2002-02-21 14:05 ` Marin David Condic 2002-02-22 16:49 ` Hyman Rosen 2002-02-22 17:22 ` Marin David Condic 2002-02-24 7:39 ` Hyman Rosen 2002-02-25 15:38 ` Matthew Heaney 2002-02-22 18:10 ` Matthew Heaney 2002-02-22 20:55 ` Hyman Rosen 2002-02-22 21:37 ` Matthew Heaney 2002-02-24 7:36 ` Hyman Rosen 2002-02-25 15:27 ` Matthew Heaney 2002-02-21 15:30 ` Matthew Heaney 2002-02-21 18:05 ` Hyman Rosen 2002-02-13 21:50 ` Eric Merritt 2002-02-14 15:08 ` Yates
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox