A couple of extensions to `with` that would be worthwhile

Paul Backus snarwin at gmail.com
Thu Oct 14 13:44:24 UTC 2021

On Thursday, 14 October 2021 at 07:12:29 UTC, Tejas wrote:
> Maybe having the syntax as:
> ```d
> with <construct> as <identifier>{
>     //do stuff
> }
> ```
> Would be better?
> It could also be useful in `Python` style management for `file` 
> handles, plus be visually distinct enough from other uses of 
> `with` to not simply be overlooked.

In D this is accomplished using a regular block scope and a 
variable declaration:

     auto <identifier> = <construct>;
     // do stuff

Python needs special syntax for it because Python doesn't have 
block scopes--the only thing that introduces a new scope in 
Python is a function.

More information about the Digitalmars-d mailing list