comp.lang.ada
 help / color / mirror / Atom feed
From: rouillard@acm.org (Jacques Rouillard)
Subject: Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
Date: 1996/12/02
Date: 1996-12-02T00:00:00+00:00	[thread overview]
Message-ID: <rouillard-0212961508370001@mac-rouillard.imt-mrs.fr> (raw)
In-Reply-To: 57uki4INNkae@maz4.sma.ch


In article <57uki4INNkae@maz4.sma.ch>, lga@sma.ch wrote:

> In article <dewar.849318953@merv>, dewar@merv.cs.nyu.edu (Robert Dewar)
writes:
> > Wiljan says

> > Seems to me that the Pascal WITH is *exactly* analogous to the Ada renaming,
> > with a little less to write, but with less flexibility.
> > 
> 
> 
> In the MacOs, you often have structures like a Rect which are
> 
> Rect = record
>   top, bottom, right, left: integer;
> end;
> 
> You are typically using WITH when you are calculating with them.  The intent
> is to make the source easier to read, and only that.  (Well, compiler might
> write more efficent code as well.)
> 
> my_rect : Rect;
> 
> with my_rect do begin  { may have a scope of many lines }
>   top    := top - top_margin;
>   right  := left + (3*(bottom - top)) div 4;
>   bottom := bottom - bot_margin;
> end;
> 
> In this case, the proposed solution would not help much.  It would be 
> preferable to work as in C: no local block, and all the fields are written
> in full.  An extra local variable cannot do any better.
> 
> my_rect.top    := my_rect.top - top_margin;
> my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
> my_rect.bottom := my_rect.bottom - bot_margin;
> 
> This is the case every time the structured type is directly the type
> of the variable at work.  No array of, pointer to, or field in a record 
> of the structured type.  The Ada renaming is quite effective when the
> structured type is deeply nested in the variable call.

Problem: the withed thing can be returned by a fonction, that may have
side effects.

 function my_rect : Rect;
 ....
 
 with my_rect do begin         (*called only once*)
   top    := top - top_margin;
   right  := left + (3*(bottom - top)) div 4;
   bottom := bottom - bot_margin;
 end;
  

 my_rect.top    := my_rect.top - top_margin;
 my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
 my_rect.bottom := my_rect.bottom - bot_margin;

(*called 3 times*)

The best approximation remains the 'renames'.

--
Jacques Rouillard t33(0)491054342 f33(0)491700659 e rouillard@acm.org
USA http://vhdl.org/~rouillard   EU http://ismea.imt-mrs.fr/~rouillar
---------------------- Va savoir, Charles --------------------------
Ne reponds pas au fou selon    |Reponds au fou selon sa demence
 sa demence, que tu ne l'egales| de peur qu'il ne soit sage
 toi aussi [Prov 26:4]         | a ses yeux [Prov 26:5]
--------------------------------------------------------------------




  reply	other threads:[~1996-12-02  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-27  0:00 Pascal to Ada translator/ aflex,ayacc GNAT ports Martin C. Carlisle
1996-11-27  0:00 ` Michael Feldman
1996-11-28  0:00   ` steved
1996-11-29  0:00     ` Robert Dewar
1996-11-29  0:00       ` Larry Kilgallen
1996-11-29  0:00       ` wiljan
1996-11-29  0:00         ` Robert Dewar
1996-11-30  0:00           ` wiljan
1996-11-30  0:00             ` Robert Dewar
1996-12-01  0:00               ` wiljan
1996-12-01  0:00                 ` Michael Feldman
1996-12-01  0:00                 ` Robert Dewar
1996-12-02  0:00           ` Laurent Gasser
1996-12-02  0:00             ` Jacques Rouillard [this message]
1996-12-02  0:00             ` Larry Kilgallen
replies disabled

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