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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!crdgw1!sunroof!hammondr From: hammondr@sunroof.crd.ge.com (Richard A Hammond) Newsgroups: comp.lang.ada Subject: Ada functions versus arrays (i.e. () vs [] ) Message-ID: <5619@crdgw1.crd.ge.com> Date: 28 Feb 90 18:56:35 GMT References: <184@trwacs.UUCP> <598@software.software.org> Sender: news@crdgw1.crd.ge.com Organization: General Electric Corporate R&D Center List-Id: In article <598@software.software.org> blakemor@software.org (Alex Blakemore) writes: >In article <184@trwacs.UUCP> epstein@trwacs.UUCP (Jeremy Epstein) writes: >> ... look at how Ada overloads symbols. For >> example, parentheses are used for parameters as well as subscripts >> (that's something that totally confuses me as an old-time C programmer). >This is a strength of Ada not an inconsistency. This way you can change >between using an array and a function to provide some info ... >This is consistent with some formal proof methods (like Tony Hoare's) >which treat array references as function calls. Logically they >have the same effect. Mathematically a function is essentially a table >anyway. Of course, there is a difference when you assign to an array >element. ... >C has some elegance but why should the programmer have to remember >when to use [] or () ? just to make the compiler easier to write ? Last point first: I think the reason is to give the programmer a cue to what is going on. Remember, the goal of C is to provide constructs which map in a straightforward way to machine code. Thus, the C programmer is interested in the difference between an array reference and a function call. Besides, functions in C have the attributes of Ada procedures and Ada functions, i.e. the Ada function is more limited than a C function(no out or in/out parameters). So in C: a = b(d,e) + f; could modify the value not just of a, but of what d and/or e pointed to (if they were access types) or d/e themselves if they are defined via macros as more complicated objects. In fact, the argument that "an array ref" is the same as a "function call" is true for mathematical functions but not Ada ones. Ada functions can have side effects, which is a software engineering deficiency in Ada. For that reason, I'd want to know when a function call is being made. Even a function without parameters, which is why I like C's "foo()" better than Ada's "foo" for calling a parameterless function. And why I'd like to distinguish between function calls and array refs. Please, I'm trying to discuss Ada and not Ada versus C, except that because C does some things wrong doesn't mean you can't steal the good ideas. Rich Hammond