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,196864e6c216ca4f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-25 08:57:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail Message-ID: <3F73107A.1060502@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to Emulate C++ Macro with Static Local Variable? References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc52.ops.asp.att.net 1064505470 24.34.139.183 (Thu, 25 Sep 2003 15:57:50 GMT) NNTP-Posting-Date: Thu, 25 Sep 2003 15:57:50 GMT Organization: Comcast Online Date: Thu, 25 Sep 2003 15:57:50 GMT Xref: archiver1.google.com comp.lang.ada:42901 Date: 2003-09-25T15:57:50+00:00 List-Id: tmoran@acm.org wrote: > I don't see how > one might do that without a preprocessor, and I don't see how one could > (portably) get hold of the Instruction Counter for storage and later > comparison, in Ada code. I showed how. You set it up so that the memoizing function is not visible. All that is visible is a constant record containing a subprogram access value. To make a call you have to make a (variable) copy of the constant, and pass that on the call. Inside the subprogram this is a new call site. Create a new access value, reset the (record) parameter to the new value, do the initial call processing, then call the (hidden) value which will be returned. This second value of the parameter calls the routine which does the actual processing sans the initial call code. This way there is no lookup or anything to be done in either case. Call the initial value in the constant, this is the first call from this site. Call the returned value, and this is a subsequent call. If you want you can either make sure that the record containing the access value is passed by reference, or add an access discriminant so that inside the first subprogram you can cache a list of call sites if you want to. -- Robert I. Eachus Ryan gunned down the last of his third white wine and told himself it would all be over in a few minutes. One thing he'd learned from Operation Beatrix: This field work wasn't for him. --from Red Rabbit by Tom Clancy.