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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,715875e575230543 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-21 16:13:13 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Thought this was funny Date: Tue, 21 Oct 2003 23:13:12 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <3F95AFE3.7030308@comcast.net> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1066777992 5387 134.91.1.34 (21 Oct 2003 23:13:12 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Tue, 21 Oct 2003 23:13:12 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:1342 Date: 2003-10-21T23:13:12+00:00 List-Id: Robert I. Eachus wrote: : Stephane Richard wrote: : :> I'm canadian and that code made me chuckle too ;-). The programmer much have :> read how to handle the enumeration type first, then read about the Boolean :> type being an enumeration of True and False maybe? ;-). : : No, he must have been taught that your program design should allow for : changes in requirements. He was prepared for another value being added : to Boolean. ;-) Or he is just a careful programmer, who knows GNAT, case statements, and Unchecked_Conversion :-) with Unchecked_Conversion; with Ada.Text_IO; use Ada; procedure test is type This_Or_That is (This, That); for This_Or_That use (That => 17, This => 4); for This_Or_That'Size use 8; type My_Truth is new Boolean; for My_Truth'Size use 8; function from_This_Or_That is new Unchecked_Conversion(This_Or_That, My_Truth); begin if from_This_Or_That(This) then Text_IO.put_line("Y"); else Text_IO.put_line("N"); end if; case from_This_Or_That(This) is when True => Text_IO.put_line("Y"); when False => Text_IO.put_line("N"); end case; end test; $ ./test Y raised CONSTRAINT_ERROR : test.adb:27 invalid data Georg