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

Edit detail for SandBoxLexicalScope revision 11 of 12

1 2 3 4 5 6 7 8 9 10 11 12
Editor: Bill Page
Time: 2008/05/15 20:57:56 GMT-7
Note: Gaby

changed:
-    even? i => 1
-    3.14
     even? i => 1
     3.14

changed:
-     x case Integer =>
-       xf := x::Integer::Float
-       y case Integer => xf**y
-       xf**y
-     x case Float =>
-       y case Integer => x ** y
-       x ** y
-     0
     if x case Integer then
       xf:=x::Integer::Float
       if y case Integer then
         xf ** y
       else
         xf ** y
     else
       if y case Integer then
         x ** y
       else
         x ** y

j is referenced out of scope

fricas
for i in 1..5 repeat
        j:Integer := i^2
        output(i::OutputForm)$OutputPackage
1 2 3 4 5
Type: Void
fricas
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:

fricas
j: Integer
Type: Void
fricas
for i in 1..5 repeat
        j := i^2
        output(i::OutputForm)$OutputPackage
1 2 3 4 5
Type: Void
fricas
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/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8452782754204589047-25px003.as
      using AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8452782754204589047-25px003.as", line 4: import from PositiveInteger ............^ [L4 C13] #9 (Error) No meaning for identifier `PositiveInteger'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8452782754204589047-25px003.as", line 7: checkscope1: () -> PositiveInteger ....................^..^ [L7 C21] #11 (Error) There are no suitable meanings for the operator `->'. [L7 C24] #10 (Error) No meaning for identifier `PositiveInteger'. [L7 C24] #13 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
The )library system command was not called after compilation.

fricas
checkscope1()
There are no library operations named checkscope1 Use HyperDoc Browse or issue )what op checkscope1 to learn if there is any operation containing " checkscope1 " in its name.
Cannot find a no-argument definition or library operation named checkscope1 .

aldor
#pile
#include "axiom"
import from PositiveInteger
CheckScope2(): with checkscope2: () -> PositiveInteger == add checkscope2():PositiveInteger == local 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/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8264748852590484820-25px005.as
      using AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8264748852590484820-25px005.as", line 4: import from PositiveInteger ............^ [L4 C13] #9 (Error) No meaning for identifier `PositiveInteger'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8264748852590484820-25px005.as", line 7: checkscope2: () -> PositiveInteger ....................^..^ [L7 C21] #11 (Error) There are no suitable meanings for the operator `->'. [L7 C24] #10 (Error) No meaning for identifier `PositiveInteger'. [L7 C24] #13 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
The )library system command was not called after compilation.

fricas
checkscope2()
There are no library operations named checkscope2 Use HyperDoc Browse or issue )what op checkscope2 to learn if there is any operation containing " checkscope2 " in its name.
Cannot find a no-argument definition or library operation named checkscope2 .

Ralf Hemmecke wrote:

Ooops, what in would be illegal? I just had to replace (as I said) the braces by parentheses, since parens are used to group sequences of commands. (Same as braces in Aldor.)

spad
)abbrev domain AAA Aaa
Aaa: with
    bar: Integer -> Integer
  == add
    (x: Integer := 4; y: Integer := 3)
    bar(a: Integer): Integer == x + a + z
    z: Integer := 3 + y
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2292316700013189339-25px007.spad
      using old system compiler.
   AAA abbreviates domain Aaa 
------------------------------------------------------------------------
   initializing NRLIB AAA for Aaa 
   compiling into NRLIB AAA 
   compiling exported bar : Integer -> Integer
****** comp fails at level 2 with expression: ******
error in function bar 
(+ (+ |x| |a|) | << z >> |) ****** level 2 ****** $x:= z $m:= $EmptyMode $f:= ((((|a| # #) (|y| # #) (|x| # #) (* #) ...)))
>> Apparent user error: cannot compile (+ (+ x a) z)

Bill Page wrote:

But this works since z is now in "scope" of the function body of bar.

spad
)abbrev domain AAA Aaa
Aaa: with
    bar: Integer -> Integer
  == add
    (x: Integer := 4; y: Integer := 3)
    z: Integer
    bar(a: Integer): Integer == x + a + z
    z: Integer := 3 + y
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6187271087318241578-25px008.spad
      using old system compiler.
   AAA abbreviates domain Aaa 
------------------------------------------------------------------------
   initializing NRLIB AAA for Aaa 
   compiling into NRLIB AAA 
   compiling exported bar : Integer -> Integer
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |Aaa| REDEFINED
;;; *** |Aaa| REDEFINED Time: 0 SEC.
Warnings: [1] bar: z has no value
Cumulative Statistics for Constructor Aaa Time: 0 seconds
finalizing NRLIB AAA Processing Aaa for Browser database: --->-->Aaa(constructor): Not documented!!!! --->-->Aaa((bar ((Integer) (Integer)))): Not documented!!!! --->-->Aaa(): Missing Description ; compiling file "/var/aw/var/LatexWiki/AAA.NRLIB/AAA.lsp" (written 26 JUL 2013 05:20:29 PM):
; /var/aw/var/LatexWiki/AAA.NRLIB/AAA.fasl written ; compilation finished in 0:00:00.017 ------------------------------------------------------------------------ Aaa is now explicitly exposed in frame initial Aaa will be automatically loaded when needed from /var/aw/var/LatexWiki/AAA.NRLIB/AAA

An example of Union for branches of if that yield different types:

spad
)abbrev domain BBB Bbb
Bbb: with
    foo: Integer -> Union(Integer,Float)
  == add
    foo(a: Integer): Union(Integer,Float) ==
     x:Union(Integer,Float)
     if a>0 then
         x := 1
     else
         x := 2.3
if x case Integer then x:=x*x else x:=x*x x
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1133161573775318814-25px009.spad
      using old system compiler.
   BBB abbreviates domain Bbb 
------------------------------------------------------------------------
   initializing NRLIB BBB for Bbb 
   compiling into NRLIB BBB 
   compiling exported foo : Integer -> Union(Integer,Float)
Time: 0.01 SEC.
(time taken in buildFunctor: 0)
;;; *** |Bbb| REDEFINED
;;; *** |Bbb| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor Bbb Time: 0.01 seconds
finalizing NRLIB BBB Processing Bbb for Browser database: --->-->Bbb(constructor): Not documented!!!! --->-->Bbb((foo ((Union (Integer) (Float)) (Integer)))): Not documented!!!! --->-->Bbb(): Missing Description ; compiling file "/var/aw/var/LatexWiki/BBB.NRLIB/BBB.lsp" (written 26 JUL 2013 05:20:29 PM):
; /var/aw/var/LatexWiki/BBB.NRLIB/BBB.fasl written ; compilation finished in 0:00:00.012 ------------------------------------------------------------------------ Bbb is now explicitly exposed in frame initial Bbb will be automatically loaded when needed from /var/aw/var/LatexWiki/BBB.NRLIB/BBB

fricas
foo(0)

\label{eq1}5.29(1)
Type: Union(Float,...)
fricas
foo(1)

\label{eq2}1(2)
Type: Union(Integer,...)

*Gaby wrote:

Try:

spad
)abbrev package BILLPAGE BillPageUnion
BillPageUnion(): Public == Private where
 Public ==> with
   foo: (Integer,Integer) -> Union(Integer,Float)
 Private ==> add
   makeU(i:Integer): Union(Integer,Float) ==
     even? i => 1
     3.14
foo(i:Integer,j:Integer):Union(Integer,Float) == x: Union(Integer,Float) := makeU(i) y: Union(Integer,Float) := makeU(i) if x case Integer then xf:=x::Integer::Float if y case Integer then xf ** y else xf ** y else if y case Integer then x ** y else x ** y
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7302843301611700278-25px011.spad
      using old system compiler.
   BILLPAGE abbreviates package BillPageUnion 
******** Spad syntax error detected ********
Expected: BACKTAB
The prior line was:
15> if y case Integer then
The current line is:
16> xf ** y
The number of valid tokens is 1. The prior token was #S(TOKEN :SYMBOL |xf| :TYPE IDENTIFIER :NONBLANK 16) The current token is #S(TOKEN :SYMBOL POWER :TYPE KEYWORD :NONBLANK 16)

fricas
foo(1,1)$BillPageUnion
You cannot now use BillPageUnion in the context you have it. foo(2,1)$BillPageUnion
You cannot now use BillPageUnion in the context you have it. foo(1,2)$BillPageUnion
You cannot now use BillPageUnion in the context you have it. foo(2,2)$BillPageUnion
You cannot now use BillPageUnion in the context you have it.

Aldor (at least, the reference manual says) so makes variable declarations `local', unless modified by `free' or `fluid' modifiers.

Specification? --hemmecke, Tue, 13 May 2008 08:23:34 -0700 reply
Gaby, on which page of the AUG is this written?