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: f891f,9d58048b8113c00f X-Google-Attributes: gidf891f,public X-Google-Thread: 1014db,9d58048b8113c00f X-Google-Attributes: gid1014db,public X-Google-Thread: 101deb,b20bb06b63f6e65 X-Google-Attributes: gid101deb,public X-Google-Thread: 103376,2e71cf22768a124d X-Google-Attributes: gid103376,public X-Google-Thread: 10cc59,9d58048b8113c00f X-Google-Attributes: gid10cc59,public From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) Subject: Re: next "big" language?? (disagree) Date: 1996/06/12 Message-ID: <4plegb$ibp@goanna.cs.rmit.EDU.AU>#1/1 X-Deja-AN: 159722572 references: <4p1l65$35qi@info4.rus.uni-stuttgart.de> <4p60nk$imd@euas20.eua.ericsson.se> <4p8lmq$oq7@goanna.cs.rmit.edu.au> <4pj8p7$h9r@goanna.cs.rmit.EDU.AU> organization: Comp Sci, RMIT, Melbourne, Australia newsgroups: comp.lang.pascal,comp.lang.c,comp.lang.misc,comp.lang.pl1,comp.lang.ada nntp-posting-user: ok Date: 1996-06-12T00:00:00+00:00 List-Id: > ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes: > > subtype Assertion is Boolean range True .. True; > > ... > > X_Is_Even: Assertion := X mod 2 = 0; > >This will raise a constraint exception if the assertion is false. > >Looks like an assertion to me. I am seeing this in comp.lang.ada, where, to preserve what tattered shreds of credibility I may perhaps retain, I should point out that this was a flip response I posted to an attack in comp.lang.misc. The last thing I wanted to do was to admit that an Ada compiler may optimise this away... rav@goanna.cs.rmit.EDU.AU (++ robin) writes: >---What is the point of this? > A declaration buried somewhere else, and a test. The declaration is *not* buried "somewhere else", but precisely where it is needed. The context is something like this: -- assume an external -- function Assertion(Condition: Boolean) return Boolean is -- begin -- if not Condition then -- raise Assertion_Violation; -- end if; -- return Condition; -- end Assertion; procedure P(X: Natural) is Precondition: constant Boolean := Assertion( X mod 2 = 0 ); ... > Why not something in clear english, which doesn't need a >reference to some other part of the program, like: > if mod(x, 2) ^= 0 then > put ('The value of x is not odd.'); (a) That is not English. (b) It is back to front: I was asserting that X *should* be even; you are printing an error mesage if the value is ok! (c) This *is* a reference to some other part of the program. The intent is, after all, to state _all_ the properties of an argument in one place. Why should the fact that X should be even be ripped apart and stated miles away from the fact that X should be a natural number? (d) A command to write a string to SYSOUT is not the same as a declaration that says that a particular condition should be true. >This has the aditional benefit that the user of the program >has a clear unequivocal message about the cause of the problem. (e) But who says there *is* a user? In C, for example, assert() raises the SIGABRT exception, which may (but need not) be handled by the program itself. (f) The message is not clear. How can you possibly expect a user to know what 'x' means? I have been the victim of programs that responded to error situations by producing symbolic dumps (any other EMAS users out there?) and it was really useless; the internal details of a program just aren't intelligible to most of its users. (g) The message is not about the cause. It is about a symptom. (h) If you want a message, I can, using goanna:~ok/Ada.d/assertions.ad{s,b}, write procedure P(X: Natural) is Precondition: constant Boolean := Assertion( X mod 2 = 0, "The frotznick count must be even" ); ... >If it's important that the whereabouts of this test be known, >the programmer can include a statement such as "signal error;" >or "signal condition (xyz);" or "put (' at line ', sourceline );" >along with the put statement. [PL/I example] The one thing that I cannot mimic in my Assertions package is C's "NDEBUG" flag. The nearest that one could get to it would be to have assertions of the form Assert(No_Debug or else (the real assertion)); Of course it _is_ possible to get this effect by using a preprocessor. The version of m4 I use has a flag to get case-insensitive macro names, so define(Assert, `null') define(Assertion, `True') would do the trick. I have used M4 to good effect with Pascal, but have so far held off using it with Ada. -- Fifty years of programming language research, and we end up with C++ ??? Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.