>> If I have something like
>>
>>
>> j: Integer := 0
>> for i in 1..5 repeat
>> j: Integer := i2
>> output(j::OutputForm)$OutputPackage
>>
>> that should not be allowed at all.
>
> Why?
---> The answer has already been given below. ;-)
>> Since it declares j twice in the same
>> scope (yes, you caught me with that "declaration" stuff).
> But, why do you think they are the same scope?
Because that is what I read from Section 8.1 AUG:
Note that the last two bind names in particular positions in the
expression, and **do not form general scope levels**.
Do you read that differently?
>> As I understand you openaxiom now introduces a new scope for the for-body.
> A loop body, where explicit for or a collect or a reduce implicitly
> introduces a scope to shield local computations from enclosing scope.
BTW, I didn't say that this is a bad thing. It only is not the way that
Aldor is specified. Maybe we should ask Stephen Watt about the
background of that design decision.
>> In Aldor the following program does not need a "free" for the j even though
>> the function body introduces a new scope.
>
> yes, the same is true in OpenAxiom.
>
>> However, if you add "j:=1;" just before "stdout" that would make j local
>
> That would still refer to the 'j' in enclosing scope - in all flavours of
> AXIOM.
>
>> according to the first sentence of Section 8.6. Unfortunately, I haven't yet
>> found that part of the AUG that says that the program below should exactly
>> behave as what the current Aldor compiler produces.
>
> That is why I'm looking at the specification. :-)
>
>> #include "aldor"
>> #include "aldorio"
>> import from Integer;
>> j: Integer := 2;
>> main(): () == {stdout << j << newline;}
>> main();
OK, here is the output. Not for Gaby, of course... ;-)
>aldor -laldor -grun aaa.as
"aaa.as", line 5: main(): () == {j:=1;stdout << j << newline;}
...............^
[L5 C16] #1 (Warning) Implicit local `j' is a parameter, local or
explicit free in an outer scope. Add a `local' declaration if this is
what you intended.
1
===
AUG Section 8.6:
Aldor will generate a warning if an implicitly local variable in a new
scope shadows a similarly named variable in an outer scope.
===
AUG Section 8.13, p. 110 (top)
A "free" declaration indicates to the compiler that the given name
references a variable in an outer scope, and that the initial assignment
to the variable should be interpreted as an assignment to the outer
variable, rather than an initialisation of a new variable.
===
It's clear then, what happens without the "free" as in the above program.
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel