|
|
|
last edited 13 years ago by test1 |
| 1 2 3 4 5 6 7 8 9 10 11 12 | ||
|
Editor: Bill Page
Time: 2008/05/13 08:25:15 GMT-7 |
||
| Note: scope issues | ||
changed: -Ralf wrote: **Ralf Hemmecke** wrote: changed: -But this works? **Bill Page** wrote: But this works since 'z' is now in "scope" of the function body of 'bar'. added: z: Integer bar(a: Integer): Integer == x + a + z removed: - bar(a: Integer): Integer == x + a + z removed: -
j is referenced out of scope
(1) -> for i in 1..5 repeat
j:Integer := i^2
output(i::OutputForm)$OutputPackage
1
2
3
4
5
output(j::OutputForm)$OutputPackage
25
The code above returns an error in OpenAxiom? 1.2.0 (Revision >= 563).
It sould be written like this:
j: Integer
for i in 1..5 repeat
j := i^2
output(i::OutputForm)$OutputPackage
1
2
3
4
5
output(j::OutputForm)$OutputPackage
25
Oddly, using j out of scope is also allowed in 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
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8452782754204589047-25px003.as
using Aldor compiler and options
-O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra
Use the system command )set compiler args to change these
options.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8452782754204589047-25px003.as", line 2:
#include "axiom"
^
[L2 C1] #1 (Error) Could not open file `axiom'.
The )library system command was not called after compilation.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 .
#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
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8264748852590484820-25px005.as
using Aldor compiler and options
-O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra
Use the system command )set compiler args to change these
options.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8264748852590484820-25px005.as", line 2:
#include "axiom"
^
[L2 C1] #1 (Error) Could not open file `axiom'.
The )library system command was not called after compilation.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.)
)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
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.
)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
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)
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 20 SEP 2026 02:29:41 PM):
; wrote /var/aw/var/LatexWiki/AAA.NRLIB/AAA.fasl
; compilation finished in 0:00:00.024
------------------------------------------------------------------------
Aaa is now explicitly exposed in frame initial
Aaa will be automatically loaded when needed from
/var/aw/var/LatexWiki/AAA.NRLIB/AAA