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,1d321b3a6b8bcab2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-02-01 03:20:14 PST Path: nntp.gmd.de!Germany.EU.net!howland.reston.ans.net!swrinde!news.uh.edu!uuneo.neosoft.com!Starbase.NeoSoft.COM!not-for-mail From: smize@Starbase.NeoSoft.COM (Samuel Mize) Newsgroups: comp.lang.ada Subject: Re: "Subtract C, add Ada" Date: 1 Feb 1995 04:23:48 -0600 Organization: NeoSoft Internet Services +1 713 684 5969 Message-ID: <3gnnfk$bfa@Starbase.NeoSoft.COM> References: <3fo2ot$su2@miranda.gmrc.gecm.com> <3g4p94$g07@cronkite.seas.gwu.edu> <3g9rf0$71k@Starbase.NeoSoft.COM> <3gebnq$7f3@cronkite.seas.gwu.edu> NNTP-Posting-Host: starbase.neosoft.com Date: 1995-02-01T04:23:48-06:00 List-Id: In article <3gebnq$7f3@cronkite.seas.gwu.edu>, David O'Brien wrote: Several things that made me think harder before I wrote. Painful, but thanks. ;-) Specifically, he wrote >Code layout and where expressions may be used is what this thread was >about. True. To bring it back around: Ada was not designed to be hard to write per se, but it *was* explicitly designed to be easy to read accurately, even when that made it harder to write. Note also, not just easy to read, but easy to read *accurately.* The designer felt that assignments embedded in expressions were easy to miss, and easy to screw up. This opinion is based, in large part, on our collective experiences with debugging C. So, Ada does not let assignment return a value. However, if it really really (not just really) makes your code better somehow, Ada provides a construct with which you can "wrap" the assignment, to make it visible that this particular assignment returns a value. This construct is the function declaration. With pragma inline and a little attention to what you are doing, this should be as efficient as an embedded expression, and should also be clearer to the maintenance programmer. For example, >...The original >C code was: > while ( (c = getchar()) == ' ' ) { /* count spaces */ } To make truly equivalent Ada code, you would need a function, probably in a shared file package, that assigns and returns the next character from the file: package Files_Like_C is C: character; function Next_Char return character; end Files_Like_C; with Text_Io; use Text_Io; package body Files_Like_C is function Next_Char return character is begin if End_Of_File then C := Ascii.Nul; -- no EOF character so using NUL else -- to emulate the C string terminator Get (C); return C; end if; end Next_Char; end Files_Like_C; Once all this infrastructure has been set up, you can code: while (Next_Char = ' ') loop null; -- count spaces here if needed end loop; Before anyone says "but look at all that code!" remember, we are recoding the interface to the standard file package, on the assumption that there is a compelling reason to put Next_Char into expressions. Sam Mize - smize@starbase.neosoft.com