🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2021

Re: Pascal-like 'with' statement feasible in C++?

#2021
From: Tom Payne
Date: Sun, 24 Sep 1995 06:04
75 lines
3113 bytes
Danny Bain (danny@computek.net) wrote:

: On 20 Sep 95 18:43:00 GMT, shankar@engr.sgi.com (Shankar Unni) wrote:

: >Kevin Lentin (kevinl@fangorn.cs.monash.edu.au) wrote:
: >> With is purely a piece of syntactical sugar (with some ugly type problems
: >> described elsewhere in this thread). It provides a way of making your life
: >> easier (or different). Not the compiler.
: >
: >It is an evil piece of syntactic sugar. Wait till these "with"'s start
: >getting nested, and have giant, 500+-line blocks inside them. Reading the
: >resultant code is a *nightmare*.

: Actually, the C++ draft includes a keyword 'using' that does what the
: Pascal 'with' keyword does and many more things.  Since C++ will have
: the concept of 'namespace', the 'using' keyword allows one to switch a
: block of code to use the names in another namespace.

: The example given is as follows:

: struct B
: 	{
: 	void f(char);
: 	void g(char);
: 	};

: struct D : B
: 	{
: 	using B::f;
: 	void f(int) { f('c'); } // calls B::f(char)
: 	void g(int) { g('c'); } // recursively calls d::g(int)
: 	}

: This applies to member functions, variables, typedefs and any other
: nested names declared or defined.


If I understand correctly, the semantics of WITH are a bit different
from those of using in that it applies to records (i.e., struct and
class objects) and causes members to appear as locally declared 
variables, shadowing others that are currently visible.

   class Whatever {
   public:
     int x;
     float y;
     void f(int i);
   };

   
   class Thingeroo {
   public:
      Watever w;
      with w;
      float g() {
         f(x);                 // w.f(w.x);
         return y;             // returns w.y
      }
   }

Syntactically, this is something like one would have if Whatever were
a base class for Thingeroo and the declaration of w were omitted.  Of
course, the WITH construction gives no dynamic binding etc..  

There are a lot of tedious details to work out with such a proposal,
e.g., ambiguity resolution and access control, but the problems are
similar to USING. 

Tom Payne (cs.ucr.edu)



[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <4427li$10l@galaxy.ucr.edu>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <MATT.95Sep14102849@physics10.Berkeley.EDU> <43k1g3$klh@engnews2.Eng.Sun.COM> <43pn06$b2k@fido.asd.sgi.com> <MATT.95Sep20163207@physics2.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: thp@cs.ucr.edu (Tom Payne)
Newsgroups: comp.std.c++
Subject: Re: Pascal-like 'with' statement feasible in C++?
Date: 24 Sep 1995 06:04:45 GMT
Organization: University of California, Riverside Department of Computer Science
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4427li$10l@galaxy.ucr.edu>
References: <MATT.95Sep14102849@physics10.Berkeley.EDU> <43k1g3$klh@engnews2.Eng.Sun.COM> <43pn06$b2k@fido.asd.sgi.com> <MATT.95Sep20163207@physics2.Berkeley.EDU>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: corvette.ucr.edu
X-Newsreader: TIN [version 1.2 PL2]
Content-Length: 2105
Originator: clamage@taumet