🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.oberon
Article #1243

The Trouble with WITH...

#1243
From: Peter Froehlich
Date: Sat, 30 Mar 1996 22:47
54 lines
2389 bytes
Hi there!

   Regarding  the  "theoretical"  problems  of  the WITH statement I humbly
request  a  clarification  from  someone with a better understanding of the
problem.  Here is what Oakwood says:

----- CUT -----
WITH and guarded variables

It  is  possible  to alter a guarded pointer variable within the scope of a
guarding WITH statement, example:

	TYPE
	  T  = RECORD END;     P  = POINTER TO T;
	  T1 = RECORD (T) END; P1 = POINTER TO T1;
	  T2 = RECORD (T) END; P2 = POINTER TO T2;
	PROCEDURE X;
	  VAR p: P; p1: P1; p2: P2;
	  PROCEDURE Y; 
	  BEGIN 
	    p := p2
	  END Y;
	BEGIN
	  NEW (p); NEW(p1); NEW(p2); p := p1;
	  WITH p: P1 DO
	    Y  (*p is now of type P2 and not P1*)
	  END
	END X;

A practical way to handle this is:

If  the  compiler  can be sure it is safe then give no warning message.  If
there  can  be  any  doubt then do give a warning message.  A sophisticated
compiler  could  automatically  insert  the  additional relevant type guard
checks.
----- CUT -----

   The way I see it, the real problem is whether the WITH statement applies
"statically"  ie.   only  to the text contained within or "dynamically" ie.
on the whole control flow initiated from within:

   - Using a "static WITH" the problem is present since the static type of
     p within Y() is P.  So the assignment of p2 to p is legal.

   - Using a "dynamic WITH" the problem disappears (IMHO) because the WITH
     would temporarily alter the static type of p to be P1, making the
     assignment in Y() illegal.  Of course, this can only be enforced at
     run-time.

Please  clear  up  my confusion (or tell me that I have properly understood
the problem).
                  _
By(T)e...   /| _ //3000 /\ People who use Pascal for serious programming |\
   Peter... \| \X/\miga \/ fall into a fatal trap.  (Brian W. Kernighan) |/
Technical Details
Message-ID: <2251891AH0002BF21H@p.froehlich.amc.cube.net>
Path: arc1-ca.pugleaf.net!amc.cube.net!p.froehlich

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!amc.cube.net!p.froehlich
From: p.froehlich@amc.cube.net (Peter Froehlich)
X-Newsreader: -- The Answer V3.06
Newsgroups: comp.lang.oberon
Subject: The Trouble with WITH...
Date: Sat, 30 Mar 1996 23:47:38 +0100
Message-ID: <2251891AH0002BF21H@p.froehlich.amc.cube.net>
Organization: AMIGA CITY - Public Amiga-BBS, Munich, Germany
X-Gateway: ZCONNECT ?? amc.cube.net [Z-NEWS 2.5d/AMIGA]
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0