login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxLexicalScope revision 3 of 12

1 2 3 4 5 6 7 8 9 10 11 12
Editor: Bill Page
Time: 2008/05/11 07:17:55 GMT-7
Note: aldor version

added:

Oddly, using j out of scope is also allowed in Aldor:
\begin{aldor}
#pile
#include "axiom"

import from PositiveInteger

CheckScope1(): with
    checkscope1: () -> PositiveInteger
  == add
    checkscope1():PositiveInteger ==
      for i in 1..5 repeat
        j:PositiveInteger := i^2
        --output(i::OutputForm)$OutputPackage
      --output(j::OutputForm)$OutputPackage
      j
\end{aldor}

\begin{axiom}
checkscope1()
\end{axiom}

\begin{aldor}
#pile
#include "axiom"

import from PositiveInteger

CheckScope2(): with
    checkscope2: () -> PositiveInteger
  == add
    checkscope2():PositiveInteger ==
      j:PositiveInteger
      for i in 1..5 repeat
        j := i^2
        --output(i::OutputForm)
        --output(j::OutputForm)$OutputPackage
      j
\end{aldor}

\begin{axiom}
checkscope2()
\end{axiom}


j is referenced out of scope

axiom
for i in 1..5 repeat j:Integer := i^2 output(i::OutputForm)$OutputPackage 1 2 3 4 5
Type: Void
axiom
output(j::OutputForm)$OutputPackage 25
Type: Void

The code above returns an error in OpenAxiom? 1.2.0 (Revision >= 563).

It sould be written like this:

axiom
j: Integer
Type: Void
axiom
for i in 1..5 repeat j := i^2 output(i::OutputForm)$OutputPackage 1 2 3 4 5
Type: Void
axiom
output(j::OutputForm)$OutputPackage 25
Type: Void

Oddly, using j out of scope is also allowed in Aldor:

aldor
#pile #include "axiom" import from PositiveInteger CheckScope1(): with checkscope1: () -> PositiveInteger == add checkscope1():PositiveInteger == for i in 1..5 repeat j:PositiveInteger := i^2 --output(i::OutputForm)$OutputPackage --output(j::OutputForm)$OutputPackage j
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/8452782754204589047-25px003.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./8452782754204589047-25px003.lsp
   Issuing )library command for 8452782754204589047-25px003
   Reading /var/zope2/var/LatexWiki/8452782754204589047-25px003.asy
   CheckScope1 is now explicitly exposed in frame initial 
   CheckScope1 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/8452782754204589047-25px003

axiom
checkscope1()
LatexWiki Image(1)
Type: PositiveInteger?

aldor
#pile #include "axiom" import from PositiveInteger CheckScope2(): with checkscope2: () -> PositiveInteger == add checkscope2():PositiveInteger == j:PositiveInteger for i in 1..5 repeat j := i^2 --output(i::OutputForm) --output(j::OutputForm)$OutputPackage j
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/8460232625034551769-25px005.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
"/var/zope2/var/LatexWiki/8460232625034551769-25px005.as", line 10: 
      j:PositiveInteger
......^
[L10 C7] #2 (Warning) Suspicious `:'.  Do you mean `local' or `default'?
   Compiling Lisp source code from file 
      ./8460232625034551769-25px005.lsp
   Issuing )library command for 8460232625034551769-25px005
   Reading /var/zope2/var/LatexWiki/8460232625034551769-25px005.asy
   CheckScope2 is now explicitly exposed in frame initial 
   CheckScope2 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/8460232625034551769-25px005

axiom
checkscope2()
LatexWiki Image(2)
Type: PositiveInteger?