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-Thread: 103376,400766bdbcd86f7c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: This can't be done in Ada...or? Date: 12 Feb 2005 14:02:52 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1108234972 31625 69.38.147.31 (12 Feb 2005 19:02:52 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 12 Feb 2005 19:02:52 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:8293 Date: 2005-02-12T14:02:52-05:00 List-Id: Duncan Sands writes: > > The compiler can optimize away everything inside the "if > > Logging_Enabled". But it can't optimize away the evaluation of the > > parameters unless it can prove the absence of side effects. > > For example: > > > > Trace.Error(..., "Bad value of X " & Debug_Info(X)); > > > > where Debug_Info is some user-defined function that produces useful > > debug info about some complicated data structure called X. > > It has no side effects, but the compiler doesn't know that, usually. > > GNAT's pragma Pure_Function might help here. Yes. Note that Pure_Function has different semantics than Pure (besides the fact that Pure_Function has finer granularity). Pragma Pure has rules that require the thing to actually *be* pure. The only way to circumvent those rules is with things like machine code inserts. But Pure_Function has no such rules: if you lie, the compiler will believe you, and your program might malfunction. Robert Dewar objected to the rules for pragma Pure during Ada 9X -- he thought it should be like Pure_Function in that regard. That's because (like all compile time rules) the rules are conservative. You can't write a memoizing function and declare it Pure, but you can declare it Pure_Function. >... Is something like that > planned for Ada 2005? Somebody answered that, "no". If I were designing the language, I would allow Pure on procedures and functions as well as library packages. I would require compile time checking. Then I would add *another* pragma to turn off the checking; this could be placed in the body. Seems like the best of both worlds: Robert can have his pure memoizing functions, but in cases where the compiler *can* check the rules, the rules are checked. - Bob