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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a187c77b231bfca6 X-Google-Attributes: gid103376,public From: stt@henning.camb.inmet.com (Tucker Taft) Subject: Re: access to subprogram disciminants Date: 1996/04/26 Message-ID: #1/1 X-Deja-AN: 151563302 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: henning.camb.inmet.com references: <4lp3sc$glg@news1.delphi.com> organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-04-26T00:00:00+00:00 List-Id: tmoran@bix.com wrote: : >What you are trying to accomplish can be done using normal record : >*components*, initialized as a result of calling a function : >or procedure. In other OOP's, such a function would often be called : >a "constructor," but in Ada, you can just use normal functions or : >procedures as "constructors." : I had thought that 'constructor' in C++ was close to 'procedure : initialize' for an Ada 95 Controlled type. Not really. The procedure Initialize of a controlled type is for *default* initialization, roughly equivalent to a parameterless constructor for C++. Constructor's with parameters are a better match for a parameterized Ada function the returns an initialized object, or a pointer to a newly allocated and initialized object. : ... I also thought that the : only parameters available to procedure 'initialize' were discriminants : or other members of the record structure being initialized. Further, : the compiler will insist that values be supplied for (non-default : valued) discriminants, whereas I can't get the compiler to enforce a : requirement for *any* values for the rest of the record components. : Am I mistaken? If the type is private, then the user will have to call one of your subprograms to initialize an object. Such subprograms can have parameters, with or without defaults. If the type is also declared with "unknown" discriminants, such as: type T(<>) is private; then the user cannot declare a default-initialized object, but rather must call one of your functions to specify the initial value. : ... : I try to think of an Ada compiler not just as a tool to do scut work : like converting code in an HLL to binary, but as a somewhat intelligent : helper guiding me away from error. Sort of like the difference between : a rod and hangers keeping my clothes off the floor, vs a gentleman's : valet suggesting that a particular tie might not be the best choice : with a particular suit. So I'm trying to arrange things so the : language and compiler will be as helpful as possible. I certainly sympathize with your goal of using the compiler to help as much as possible. However, I don't think discriminants are the most appropriate way to accomplish this particular kind of parameterization. Functions with parameters are much more flexible, and if used appropriately, more efficient. -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA