[M3devel] introducing VAR in more places?

Mika Nystrom mika at async.caltech.edu
Tue Feb 12 14:41:31 CET 2008


hendrik at topoi.pooq.com writes:
>On Mon, Feb 11, 2008 at 10:17:13PM -0600, Rodney M. Bates wrote:
>> I don't think this is what Tony meant.  In C++, an opening brace
>> starts a block, but every local declaration in that block has its own
>> unique scope that only starts at that declaration and goes to the end
>> of the block.  This is particularly messy because the local declarations
>> of a block need not all precede all the statements,
>
>That is, in my opinion, one of the few things that C and C++ did right, 
>well, almost right.  It permits a coding style in which every 
>variable declaration is initialised, and is declared if and only if it 

You can do all kinds of fun stuff with C's declarations/initializations.

switch (a) {
  int x=7;
  case 0:
    use(x); /* oops */
  ...
}

goto somewherefun;

{
  int y=7;

somewherefun:
  use(y); /* oops again */
}


>has a value.  Now that's a useful property.  It fails for recursion, 
>so there are limits in how far it can apply.  And when coding like this, 
>you want the simplest syntax to define a constant identifier -- one 
>whose value cannot be rebound except by reexecuting the entire block.  
>Making something that can change should require more effort -- like 
>adding a keyword "var" or some such.

Sounds to me like you're talking about Modula-3's WITH!

     Mika



More information about the M3devel mailing list