comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: C like op= proposal
Date: 1999/08/18
Date: 1999-08-18T19:39:31+00:00	[thread overview]
Message-ID: <yeck8qsev4d.fsf@king.cts.com> (raw)
In-Reply-To: Pine.SUN.3.91-FP.990818113007.5192A-100000@cap1.capaccess.org

Jeff Carter <jcarter@CapAccess.org> writes:
[...]
> One problem with this kind of syntax can be seen from the following example:
> 
> type Rec is record
>    I : Integer;
> end record;
> 
> type Rec_Ptr is access all Rec;
> 
> Count : Natural := 0;
> 
> function Side_Effects return Rec_Ptr is
>    Result : Rec_Pointer := new Rec;
> begin -- Side_Effects
>    Count := Count + 1;
>    Result.I := Count;
> 
>    return Result;
> end Side_Effects;
> 
> ...
> 
> Side_Effects.I := @ + @ / 2 + 1;
> 
> What is the value of Count after executing this statement?

No problem; the value of Count is 1.  An occurrence of @ doesn't cause
the left hand side to be re-evaluated, it merely refers to the object
whose name has already been evaluated.  (At least that's how I'd
define it.)

More precisely, the statement

    Side_Effects.I := @ + @ / 2 + 1;

would be equivalent to

    declare
       _LHS_ : _some_type_ renames Side_Effects.I;
    begin
        _LHS_ := _LHS_ + _LHS_ / 2 + 1;
    end;

with the proper substitutions for _LHS_ and _some_type_.

I don't think defining the semantics is terribly difficult.  The real
issue is that most people here seem to think it's unbearably ugly.  I
don't agree -- it's not exactly pretty, but I think the convenience
would be worth it.  Perhaps I've been contaminated by several years of
C and Perl.  I suspect a syntax other than @ would make it more
bearable to some -- perhaps a new reserved word.

Others have suggested things like a generic Inc procedure or a renames
declaration to achieve similar effects.  These work, but I haven't
seen them used much in practice.  The reason: they both require an
extra declaration, and possibly a new scope, for something that's
supposed to be a shorthand within a single assignment statement.

Remember that C's funky operators like ++, +=, and so on are dangerous
largely because they have side effects *and* return results.  (So does
ordinary assignment.)  The proposed @ shorthand doesn't have this
problem.  For example, C lets you write thinks like "i = i++", which
produces undefined behavior; the @ shorthand doesn't allow such
things.

I'm well aware that there's little or no chance of this being added to
some future version of Ada (which makes this whole thread somewhat
off-topic, I suppose).  I'm just saying that I like the idea, and I
wouldn't mind seeing it in some future language.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
One of the great tragedies of ancient history is that Helen of Troy
lived before the invention of the champagne bottle.




  reply	other threads:[~1999-08-18  0:00 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-15  0:00 C like op= proposal Brian Rogoff
1999-08-15  0:00 ` Ray Blaak
1999-08-15  0:00   ` Brian Rogoff
1999-08-16  0:00     ` Gautier
1999-08-17  0:00       ` John Duncan
1999-08-17  0:00         ` Gautier
1999-08-17  0:00       ` Samuel Tardieu
1999-08-17  0:00         ` Gautier
1999-08-17  0:00         ` Andi Kleen
1999-08-18  0:00           ` Robert Dewar
1999-08-17  0:00             ` Brian Rogoff
1999-08-18  0:00               ` Ted Dennison
1999-08-18  0:00                 ` Robert I. Eachus
1999-08-18  0:00                 ` Jeff Carter
1999-08-18  0:00                   ` Keith Thompson [this message]
1999-08-19  0:00                     ` Michael F. Yoder
1999-08-21  0:00                       ` Keith Thompson
1999-08-19  0:00                     ` Tarjei T. Jensen
1999-08-19  0:00                       ` Robert Dewar
1999-08-20  0:00                         ` P.S. Norby
1999-08-21  0:00                           ` Robert Dewar
1999-08-19  0:00                       ` Lance Kibblewhite
1999-08-19  0:00                       ` tmoran
1999-08-19  0:00                       ` Ted Dennison
1999-08-18  0:00               ` Gautier
1999-08-18  0:00               ` Robert Dewar
1999-08-18  0:00                 ` Brian Rogoff
1999-08-19  0:00                   ` Robert Dewar
1999-08-21  0:00                     ` Brian Rogoff
1999-08-23  0:00                     ` Robert A Duff
1999-08-18  0:00             ` Andi Kleen
1999-08-18  0:00         ` Gautier
1999-08-16  0:00 ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox