|
|
|
last edited 14 years ago by hemmecke |
| 1 | ||
|
Editor: hemmecke
Time: 2011/11/29 05:29:41 GMT-8 |
||
| Note: | ||
changed: - And below an Aldor version of the Fibonacci function that resembles a definition done in Haskell. \begin{aldor} #include "axiom" Z ==> Integer; ZZ ==> Z -> Z; -- Haskell -- fiblist = 1 : 1 : (zipWith (+) fiblist (tail fiblist)) import from Z; zipWith(op: (Z,Z)->Z, f: ZZ, g: ZZ)(x: Z): Z == op(f x, g x); apply(z: Z, zz: ZZ)(x: Z): Z == if zero? x then z else zz(x-1); tail(zz: ZZ)(x: Z): Z == zz(x+1); fib(x: Z): Z == (1 1 zipWith(+, fib, tail fib)) x; \end{aldor} \begin{axiom} [fib n for n in 1..10] \end{axiom} And here the same program written for Aldor without PanAxiom. Compile and run as follows: aldor -laldor -fx fib.as && ./fib \begin{aldor} #include "aldor" #include "aldorio" Z ==> Integer; ZZ ==> Z -> Z; import from Z; zipWith(op: (Z,Z)->Z, f: ZZ, g: ZZ)(x: Z): Z == op(f x, g x); apply(z: Z, zz: ZZ)(x: Z): Z == if zero? x then z else zz(x-1); tail(zz: ZZ)(x: Z): Z == zz(x+1); fib(x: Z): Z == (1 1 zipWith(+, fib, tail fib)) x; main(): () == { import from List Z; stdout << [fib n for n in 1..10] << newline; } main(); \end{aldor}
And below an Aldor version of the Fibonacci function that resembles a definition done in Haskell.
(1) -> <aldor> #include "axiom" Z ==> Integer; ZZ ==> Z -> Z; -- Haskell -- fiblist = 1 : 1 : (zipWith (+) fiblist (tail fiblist)) import from Z; zipWith(op: (Z,Z)->Z, f: ZZ, g: ZZ)(x: Z): Z == op(f x, g x); apply(z: Z, zz: ZZ)(x: Z): Z == if zero? x then z else zz(x-1); tail(zz: ZZ)(x: Z): Z == zz(x+1);
fib(x: Z): Z == (1 1 zipWith(+,fib, tail fib)) x;</aldor>
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1094142832394199181-25px001.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/1094142832394199181-25px001.as", line 1:
#include "axiom"
^
[L1 C1] #1 (Error) Could not open file `axiom'.
The )library system command was not called after compilation.[fib n for n in 1..10]
There are no library operations named fib Use HyperDoc Browse or issue )what op fib to learn if there is any operation containing " fib " in its name. Cannot find a definition or applicable library operation named fib with argument type(s) PositiveInteger
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are no library operations named fib Use HyperDoc Browse or issue )what op fib to learn if there is any operation containing " fib " in its name.
Cannot find a definition or applicable library operation named fib with argument type(s) PositiveInteger
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.
And here the same program written for Aldor without PanAxiom. Compile and run as follows: aldor -laldor -fx fib.as && ./fib
#include "aldor" #include "aldorio"
Z ==> Integer; ZZ ==> Z -> Z;
import from Z; zipWith(op: (Z,Z)->Z, f: ZZ, g: ZZ)(x: Z): Z == op(f x, g x); apply(z: Z, zz: ZZ)(x: Z): Z == if zero? x then z else zz(x-1); tail(zz: ZZ)(x: Z): Z == zz(x+1);
fib(x: Z): Z == (1 1 zipWith(+,fib, tail fib)) x;
main(): () == { import from List Z; stdout << [fib n for n in 1..10] << newline; }
main();
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/5940177716537504213-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.
Compiling Lisp source code from file
./5940177716537504213-25px003.lsp
Issuing )library command for 5940177716537504213-25px003
Reading #P"/var/aw/var/LatexWiki/5940177716537504213-25px003.asy"
zipWith is now explicitly exposed in frame initial
apply is now explicitly exposed in frame initial
tail is now explicitly exposed in frame initial
fib is now explicitly exposed in frame initial
main is now explicitly exposed in frame initial