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,ce0900b60ca3f616 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-05 05:56:16 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: Side-Effects in Functions [Rosen Trick] Date: 5 Nov 2001 05:56:15 -0800 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0111050556.1f9137ff@posting.google.com> References: <9rue9f$j4t$1@nh.pace.co.uk> <9ruiet$kqg$1@nh.pace.co.uk> <3BE3235D.E292B890@boeing.com> <3BE35498.9F6381A2@acm.org> <9s230d$107b5a$2@ID-25716.news.dfncis.de> <5ee5b646.0111040507.5ca7ea23@posting.google.com> <9s3tl3$111hco$1@ID-25716.news.dfncis.de> <5ee5b646.0111041846.93f3e07@posting.google.com> <9s5eub02j61@drn.newsguy.com> NNTP-Posting-Host: 205.232.38.14 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1004968576 24540 127.0.0.1 (5 Nov 2001 13:56:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Nov 2001 13:56:16 GMT Xref: archiver1.google.com comp.lang.ada:15802 Date: 2001-11-05T13:56:16+00:00 List-Id: pete@nospam wrote in message news:<9s5eub02j61@drn.newsguy.com>... > functions, in the mathemtical sense, do not accept an IN OUT paramters, > and do not have side effects. > > y=f(x), x here can never be modified by the function f(). > > so, Ada function is more like a math function. Yes of course, that is the naive view that might be taught in a beginning course, but it is bogus. Sure, Ada functions can be used to model mathematical functions, that's true in any case, but Ada functions are not a bit like math functions. Mathematical functions cannot take pointer arguments allowing modification of the calling variable, mathematical functions cannot generate output on files, mathematical functions cannot modify global variables. Mathematical functions are very restrictive, and the language makes no attempt to limit the semantics to functions that have some sensible meaning as mathematical functions. That's the whole point here. Functions in Ada DO allow side effects quite freely, and what seems odd is the Ada rule in this case: Functions are allowed to have side effects, providing that there is no trace of this in the function specification :-) The real issue here, and the point at which this becomes significant, is that we use functions in Ada for interfacing to foreign languages and there the restriction is quite onerous, as anyone who has designed bindings to C knows. Yes, access parameters help, but the requirement that access parameters be non-null means that this usage often is inapplicable. For an example of functions that modify their parameters, which is in fact possible in GNAT in some cases, using implementation dependent features, see gnat.spitbol.patterns (g-spipat.ads). Here the goal was to model SNOBOL-4 style as closely as possible, and in some cases, functions modifying their parameters lead to the most natural usage from a SNOBOL-4 point of view. Since the point of this package is to assist in translation of existing SNOBOL-4 programs, stylistic considerations are significant. If (important criterion) you are familiar with SNOBOL4, feel free to suggest other approaches that would avoid this usage, I didn't find anything as convenient, and would have preferred being able to program this in a more direct manner.