with(a,b,c, ...) blocks..

Era Scarecrow rtcvb32 at yahoo.com
Tue Oct 16 21:03:57 PDT 2012


  I haven't found this specific topic anywhere in the archives so 
I'll throw it out there for feedback.

[quote] TDPL pg. 81
  "There is no ambiguity-related danger in using nested 'with's 
because the language disallows shadowing of a symbol introduced 
by an outer with by a symbol introduced by an inner with. In 
brief, in D a local symbol can never shadow another local symbol"
[/quote]

  Technically 'with' blocks can be placed just about anywhere you 
could run normal code (and sometimes replaces blocks), however 
there are cases where I'm required to use extra braces. Mind you 
this is minor syntactical issues, but..

   enum E {}
   enum F {}
   enum G {}

currently:

   void func()
   //in/out contracts
   body {
     with (E) {

     }
   }

block replacement:

   if () {
   } else with(E) {
     //
   }

Theoretically legal...

   void func()
   //in/out contracts
   body with (E) { //with replaces normal block

   }

  The above refuses to compile, however I don't feel I'd need an 
extra level of indentation, and since it's static data like Enums 
perhaps you'd want multiples. Last 'with' only accepts one 
argument, but I wonder if it wouldn't hurt to enter multiple. 
Mind you it will still error during compiling if there's 
ambiguity. This makes more sense with enums and statically known 
data vs variables.

   with(E) {
     with(F) {
       with(G) {
         //code
       }
     }
   }

or (better, TDPL pg. 81)

   with(E) with(F) with(G) {
     //code
   }

vs

   with(E, F, G) {
     //code
   }

  Perhaps a feature request. I know it's not essential so I won't 
try and push it, but syntactical sugar can't hurt right?


More information about the Digitalmars-d-learn mailing list