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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,10444cff97404845 X-Google-Attributes: gid103376,public From: Gautier Subject: Re: C like op= proposal Date: 1999/08/16 Message-ID: <37B7D172.DCE02FFA@Maths.UniNe.CH>#1/1 X-Deja-AN: 513301161 Content-Transfer-Encoding: 7bit References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-08-16T00:00:00+00:00 List-Id: > It's certainly not any more than syntactic sugar, but if I were designing > my own Ada like language from scratch, would it be worth including > such a facility? Into the language I think it would be an overload. But there are situation where there is not a:= a + 1; or a:= a + b; which is at the same time more readble than the "++"s macro-assembler counterparts _and_ transformed into "++"s by optimizers, _but_ a(b(c,d+e(f,g)).h(i,j)) := a(b(c,d+e(f,g)).h(i,j)) + 1; which can be horribily long and unlikely to be catched by the optimizer -> 2x too slow (at least: the extra code makes a penalty for processor cache). I these cases there are some solutions: - A "renames". But you have to make a declare..begin..end block each time :-( - Inlined procedures "Inc", "Add" etc. This is much better... Both solutions may produce code near to a "a(b(c,d+e(f,g)).h(i,j))++" but it has to be verified. I'm using a generic Add_Inc package - but I'm sure that a standard Ada.* equivalent with "intrinsic" pragmas would be the best solution! generic type pm_elt is private; one: pm_elt; with function "+" (left,right:pm_elt) return pm_elt is <>; with function "-" (left,right:pm_elt) return pm_elt is <>; package Add_Inc is procedure Add(a:in out pm_elt; b:pm_elt); procedure Sub(a:in out pm_elt; b:pm_elt); procedure Inc(a:in out pm_elt); procedure Dec(a:in out pm_elt); end; package body Add_Inc is procedure Add(a:in out pm_elt; b:pm_elt) is begin a:= a+b; end; procedure Sub(a:in out pm_elt; b:pm_elt) is begin a:= a-b; end; procedure Inc(a:in out pm_elt) is begin a:=a+one; end; procedure Dec(a:in out pm_elt) is begin a:=a-one; end; pragma Inline(Add,Sub,Inc,Dec); end; -- Gautier -------- http://members.xoom.com/gdemont/