On Sun, May 11, 2008 at 5:40 PM, Francois Maltey wrote: > ... > And how can I code the really usual Pascal/Basic/C/maple example : > > S := 0 > for i in 1..10 repeat S := S+i^2 > S > > This is one of the most usual and first examples in algorithmic > course, and axiom might not be so different than other languages, > if we want that people uses it. The demonstration I done last week > confirm this. > > What is the right method with aldor and fresh OpenAxiom ?
It works exactly as you have specified in all versions. The recent change by Gaby does not affect this at all. In fact this is exactly the programming pattern that the new version of OpenAxiom is intending to make manditory: S must first be declared *outside* the scope of the 'for' loop - as you have done implicitly above. If the value of S is to be known when the loop terminates. Because there is no declaration of S inside the 'for' loop, S refers to the *same* S as that outside the loop. So this is ok. Of course if you write this in SPAD (any flavor) or Aldor then you must also specify the type: test():Integer == S:Integer := 0 for i in 1..10 repeat S := S+i^2 S > Or where am I wrong ? > Why do you think something is wrong? If you wrote: for i in 1..10 repeat S := i^2 S (without any previous mention of S) that would be wrong. S would not be know outside the loop. In previous versions of Axiom and in Aldor this is allowed. But it should be considered a poor programming practice and can lead to "semantic errors" during the SPAD compile. Gaby's change makes this construction illegal and prevents these semantic errors. In the new version of SPAD at least a declaration of S is required outside of the loop: S:Integer for i in 1..10 repeat S := i^2 S even if no value is supplied in the outer loop. Regards, Bill Page. ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ open-axiom-devel mailing list open-axiom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open-axiom-devel