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,FREEMAIL_FROM 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-24 20:27:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!west.cox.net!east.cox.net!peer01.cox.net!cox.net!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!53ab2750!not-for-mail From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5b) Gecko/20030901 Thunderbird/0.2 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: <3F722C53.9020808@attbi.com> In-Reply-To: <3F722C53.9020808@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 25 Sep 2003 03:27:19 GMT NNTP-Posting-Host: 162.83.244.79 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny03.gnilink.net 1064460439 162.83.244.79 (Wed, 24 Sep 2003 23:27:19 EDT) NNTP-Posting-Date: Wed, 24 Sep 2003 23:27:19 EDT Xref: archiver1.google.com comp.lang.ada:42874 Date: 2003-09-25T03:27:19+00:00 List-Id: Robert I. Eachus wrote: > This code is a bit ugly, but it does compile. And since Bar_Pointer is > a constant, you can't accidently pass it to Test. There might be a > cleaner cleverer way to do it, but this works. > > The cleanest option may be to run your code through a preprocessor and > use a similar macro. Robert, I'm almost ashamed of you! You're abandoning your Ada ways and starting to think like a C++ hacker! :-) The whole design is wrong in the C++ to begin with. If you want to have a memoizing function, the job of caching old values belongs to the function itself, not scattered in macros and variables all over the place. In Ada, I suppose that I would just stick bar(foo:integer) into a package, then have one of the Charles maps in the same package to hold memoized values. There are lots of variations if allocation is forbidden, or if memoization must be controlled from the call site, but none of them should require sprinkling statics all over the place.