From: Tucker Taft <stt@averstar.com>
Subject: Re: Why default values not taken?
Date: Tue, 12 Jun 2001 11:04:14 -0400
Date: 2001-06-12T15:04:14+00:00 [thread overview]
Message-ID: <3B262F6D.BD69FB9F@averstar.com> (raw)
In-Reply-To: mailman.992354057.29715.comp.lang.ada@ada.eu.org
"M. A. Alves" wrote:
>
> I want to create an object with only some components different from their
> default values e.g.
>
> Contact_Person := new Text_Item'(Remark => US("name and email"));
>
> where Text_Item inherits Remark from Input_Item and adds Text, both
> defaulting to Null_Unbounded_String:
>
> type Input_Item is tagged record
> Remark: Unbounded_String;
> end record;
>
> type Text_Item is new Input_Item with record
> Text: Unbounded_String;
> end record;
>
> Of course I get the compile error "no value supplied for component Text".
>
> But do I really have to supply values for all components? What is the
> best idiom here?
Aggregates must be complete. Default expressions for record
components are only used for default initializations.
I would recommend you define a "constructor" function
or procedure, with an aggregate inside the subprogram.
You can use defaulted parameters to minimize
the amount of information a given call on the
constructor needs to specify.
In general, there are various good software-engineering
reasons to minimize the use of aggregates outside the package
where a type is defined. This pragmatic issue with defaults
just reinforces the situation.
> Thanks,
>
> --
> ,
> M A R I O data miner, LIACC, room 221 tel 351+226078830, ext 121
> A M A D O Rua Campo Alegre, 823 fax 351+226003654
> A L V E S P-4150 PORTO, Portugal mob 351+939354002
--
-Tucker Taft stt@avercom.net http://www.avercom.net
Chief Technology Officer, AverCom Corporation (A Titan Company)
Burlington, MA USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/~stt)
next prev parent reply other threads:[~2001-06-12 15:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-12 14:53 Why default values not taken? M. A. Alves
2001-06-12 15:04 ` Tucker Taft [this message]
2001-06-12 15:48 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox