Ralf Hemmecke <[EMAIL PROTECTED]> writes: | Forwarded with the permission of Stephen Watt. | | On 05/13/2008 05:30 PM, Stephen Watt wrote: | > Hi Ralf, | > | > For does not introduce a new scope for its body for a few reasons: | > | > 1. In languages like C any compound statement is a new scope so we | > have new scopes for loop bodies, branches of if-s etc.
Note that in C++ (and some other Algol-like languages), an if-statement introduces a scope for each branch. Unrealted to this (and way before I left yesterday), I was planning to send another message on that topic. Currently, Spad does not introduce a scope for each branch of an if-statement, and that can lead to surprises. There is a `semantic error' building the algebra on that speicifc point. | > | > This does not interact well with implicitly local variables. | > | > If a new variable is by default local to the smallest enclosing | > scope, then new variables would be visible only in overly small | > regions. Yes. When I do computations in for loops, I want the local variables to stay local to the loop. I don't want them to pollute the enclosing scope. | > | > E.g. suppose compound statements were scopes, then | > | > if foo? then a := 1 else { f(); a := 2 } | > | > would give unexpected results. Not in OpenAxiom if written as a: Integer if foo? then a := 1 else { f(); a := 2 } The rule in OpenAxiom is: if there is a visible name, then it is taken unless it is a definition (e.g. variable + typespecification + := + value) . Otherwise, it is implicit declaration local to the enclosing scope. | > 2. It is convenient to be able to test the last value that a for loop | > index reached. | > | > 3. Since the language allows goto, it is useful to be able to reduce | > structured control flow to the goto case. Spad does not have goto. | > I admit that none of these are absolutely compelling. So I should add | > that we tried it the other way, and this way made coding the library | > easier. -- Gaby ------------------------------------------------------------------------- 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