On Tue, May 13, 2008 at 5:32 AM, Ralf Hemmecke wrote:
>
> If all this discussion, however is just to enforce the programmer to
> create the variable j before the loop then I am all for it.

Yes, plus the clear definition of "scope", i.e. when is the variable
"known" outside of a given context.

> But don't let
>
>  j := 0
>
> be different from
>
>  j: Integer := 0
>
> if the compiler would be able to infer an appropriate type in the first
> case.
>

The alternative, I guess would be to introduce a new keyword in SPAD
like "local" in Aldor. Is that would you are recommending? Note: This
would still make some existing code in the Axiom library incorrect
since as Gaby noted there are some cases where a variable is
introduced inside a loop and the program expects this variable to be
visible outside the scope. In my opinion this is a bad coding practice
and the compiler should enforce this error.

>
> Gaby, since you certainly know that you deviate (with your decision)
> from Aldor, you should explain your new scoping rules. What, for example,
> will happen in the case of while loops? Does now every brace (i.e. every
> indentation) introduce a new scope?
>

In my opinion, having learned both Algol and Simula early in life and
"C" just a little later, I would answer: Yes, every code indentation
should introduce a new scope.

> What will be the behaviour of the following piece of code (see AUG p.100)?
>
> {
>  x: Integer := 4;
>  y: Integer := 3;
> }
> adds(a: Integer): Integer == x + a + z;
> z: Integer := 3 + y
> ...
>

There are no braces in SPAD, so there is no way to group code in this
way without some additional control structure. But in the case of,
say:

   for i in 1..1 repeat
     x: Integer := 4
     y: Integer := 3

  adds(a: Integer): Integer == x + a + z

  z: Integer := 3 + y

The 'for' loop does nothing useful. x and y have no known type in the
outer context so this would result in a compile error.

Regards,
Bill Page.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
open-axiom-devel mailing list
open-axiom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel

Reply via email to