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,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-30 06:27:26 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X Date: Fri, 30 May 2003 13:27:25 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <6a90b886.0305262344.1d558079@posting.google.com> <3ED41344.7090105@spam.com> <3ED46D81.FF62C34F@0.0> <3ED46E07.4340CABC@0.0> <3ED4F3FD.A0EF7079@alfred-hilscher.de> <3ED4ECFC.5060000@cogeco.ca> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1054301245 21716 217.17.192.37 (30 May 2003 13:27:25 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Fri, 30 May 2003 13:27:25 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:38090 Date: 2003-05-30T13:27:25+00:00 List-Id: * Robert A Duff wrote: > Correctly? I guess it depends on what you want it to do. > My example: > > Some_Array[Get_Next_Position] := Some_Array[Get_Next_Position] + 1; > > is highly unlikely to be correct, since it evaluates Get_Next_Position > twice (which is probably not what you want) and it does it in either > order (which is almost certainly not what you want). More likely, it's > just a mistake, and the programmer wanted the semantics provided by your > renaming above (or, more concisely and readably, C's += operator). Ack. with Ada.Text_IO; procedure t is type offset is range 1 .. 9; type base is range 1 .. 19; type field is array(offset) of base; f : field := (1, 2, 3, 4, 5, 6, 7, 8, 9); o : offset := f'First; t : offset; function getnext return offset is begin o := o + 1; return o; end getnext; procedure print is begin Ada.Text_IO.Put_Line("f(" & offset'Image(o) & " ) =" & base'Image(f(o))); end print; procedure printall is begin for i in f'Range loop Ada.Text_IO.Put(base'Image(f(i))); end loop; Ada.Text_IO.New_Line; end printall; begin printall; t := getnext; print; f(getnext) := f(getnext) + 10; print; printall; declare x : base renames f(getnext); begin x := x + 10; end; print; printall; declare procedure Inc(x : in out base) is begin x := x + 10; end Inc; begin Inc(f(getnext)); end; print; printall; end; Results in: 1 2 3 4 5 6 7 8 9 f( 2 ) = 2 f( 4 ) = 4 1 2 14 4 5 6 7 8 9 f( 5 ) = 15 1 2 14 4 15 6 7 8 9 f( 6 ) = 16 1 2 14 4 15 16 7 8 9 Renaming and Procedural Increment has the required behavior. Doubling the side effect argument does not. The corresponding C-Source is: #include int o = 0, f[10] = {1,2,3,4,5,6,7,8,9}; int getnext(void) { return ++o; } void print(void) { printf("f(%d) = %d\n", o, f[o]); } void printall(void) { int i; for(i = 0; i < sizeof(f)/sizeof(*f); i++) { printf("%d ", f[i]); } puts(""); } void inc(int * x) { *x = *x + 10; } int main(void) { int t; printall(); t = getnext(); print(); f[getnext()] = f[getnext()] + 10; print(); printall(); f[getnext()] += 10; print(); printall(); inc(&f[getnext()]); print(); printall(); } You find it ugly to pass an "in out" parameter using a pointer? You find it ugly to rename a expression in order to prevent reevaluation? Yes. Either language has some common idioms you will find ugly.