#include "aldor"
#include "aldorio"

main(): () == {
        import from Integer;
        for i in 1..5 repeat {
                j: Integer := i*i;
                stdout << i << newline;
        }
--      stdout << "i = " << i << newline;
--: > aldor -laldor -grun aaa.as
--: "aaa.as", line 10:         stdout << "i = " << i << newline;
--:                    ............................^
--: [L10 C29] #1 (Error) No meaning for identifier `i'.
        stdout << "j = " << j << newline;
}
main();

--: > aldor -laldor -grun aaa.as
--: 1
--: 2
--: 3
--: 4
--: 5
--: j = 25

The Aldor 1.1.0 behaves as specified in the AUG (Section 8.1 "Scopes").

On 05/11/2008 07:56 PM, Gabriel Dos Reis wrote:
 > "Bill Page" <[EMAIL PROTECTED]> writes:
 >
 > | On Sun, May 11, 2008 at 12:47 PM, Martin Rubey wrote:
 > | >
 > | > ...  Moreover, what should
 > | >
 > | >         j: Integer := 0
 > | >         for i in 1..5 repeat
 > | >                 j: Integer := i^2
 > | >         output(j::OutputForm)$OutputPackage
 > | >
 > | > output?
 > |
 > | I would expect 0.

I wouldn't. In fact, if then

         j: Integer := 0
         for i in 1..5 repeat
                 j := i^2
          output(j::OutputForm)$OutputPackage

should output 25, I would find this confusing.

For me

   j: Integer

is *not* a declaration of a variable. In fact, (if I am not mistaken) 
there are no variable declarations in Aldor (SPAD may be different 
here). Aldor is not C.

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. 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.

 > | http://www.aldor.org/docs/aldorug.pdf#page=115
 > |
 > | "New scopes in Aldor are introduced by the following expressions:
 > |
 > | - E where Definitions
 > | - +->
 > | - with
 > | - add
 > | - for i in ...
 > | - Applications, e.g. Record(i: Integer == 12)
 > |
 > | These forms may be nested to any depth. Note that the last two bind
 > | names in particular positions in the expression, and **do not form
 > | general scope levels**.

 > Note that in Aldor, you have two more constructs:
 >   * free: you use this to prevent the Aldor compiler from making
 >           the declaration/definition local by instructing it to match
 >           it with a declaration in enclosing scope.
 >           I do not seem to see where the reference manual says what
 >           happens when there is no enclosing declaration.
 >           (Perhaps an error? A silent promotion?)

 >   * fluid: you use this to prevent the Aldor compilet from making the
 >           declaration/definition local; the variable becomes dynamic.

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?

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
...


Ralf

-------------------------------------------------------------------------
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