From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada-france.org
Subject: Re: a beginner question
Date: Thu, 21 Oct 2004 12:47:39 +0100
Date: 2004-10-21T12:47:39+01:00 [thread overview]
Message-ID: <mailman.44.1098359281.10401.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <10b97a973c8cc17010b8a5e9d55be273@localhost.talkaboutprogramming.com>
Discriminated types don't let you do indiscriminated things on them :-)
Proficiency with discriminated types is a big part of being an Ada
expert. Read the chapter on discriminated types of an Ada textbook.
Ben-Ari's or Barnes'es.
In the meanwhile and for the things you seem to be trying to do you can
safely use a normal type and constructor functions.
mr1yh1 wrote:
> i am very new in ada , i try to write codes from book and see result
> i tried something but i couldnt get a good result
> (i use gnat)
>
> ******************
> with Ada.Text_Io;use Ada.Text_Io;
> procedure test is
> type Sex_T is
> (Male,
> Female);
>
> type Person ( S:Sex_T:=Male )is
> record
> Age:Positive ;
> Sex:Sex_T:=S;------please look at here first
> case S is
> when Male =>
> Has_Wife:Boolean ;
> when Female=>
> Has_Husband:Boolean;
> end case;
> end record;--person end
> Me : Person;
> she : Person (Female); ---- and this one ,
> begin
> Me:=(
> S => Male,
> Sex => Male,
> Age => 33,
> Has_Wife => True);
> she:=(
> S => Female,
> Sex => Male, ---please look at here now!!!!!
>
> Age => 23,
> Has_Husband => True);
> Put(Sex_T'Image(she.Sex));
> end test;
>
> ****
> there is not any alert
> and result is
> " male " ??
>
> if i dont put "sex=>male" , or "sex=>female"
> it dont let me to use a named association...
>
> even is i dont put " s=> female "
> it dont let me too ,
> but i said about discriminant
> when i declare the variable ( she : person(female) )
>
> why its not possible ?
> to put
> she:=(age=>23,has_husband=>true);
>
>
> regards
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
next prev parent reply other threads:[~2004-10-21 11:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-20 23:01 a beginner question mr1yh1
2004-10-20 23:53 ` Björn Persson
2004-10-21 11:47 ` Marius Amado Alves [this message]
2004-10-21 18:16 ` mr1yh1
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox