|
|
last edited 16 years ago by Bill Page |
1 2 | ||
Editor: Bill Page
Time: 2008/03/14 19:05:48 GMT-7 |
||
Note: calling PRINC |
added:
Here is a simple way to output a string by calling the Lisp function PRINC.
\begin{aldor}
#include "axiom.as"
output(x:String):Void == {
import { PRINC: (String) -> Void } from Foreign Lisp;
PRINC(x);
}
\end{aldor}
Try it.
\begin{axiom}
output("stuff")
\end{axiom}
Due to that I want to call external library functions from within Aldor/Axiom I did some trials with Aldors "Foreign" and GCL "defentry" commands.
First of all, an example that work (partly), adapted from the aldor users guide.
The following definition needs to be compiled by lisp:
(defentry |myprintf| (string) (int "printf"))
; compiling file "/var/aw/var/LatexWiki/8624266922497102717-25px001.lisp" (written 04 APR 2022 08:16:59 PM):
; /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8624266922497102717-25px001.fasl written ; compilation finished in 0:00:00.012
>> System error: The variable |myprintf| is unbound.
When this is compiled inside Axiom, the symbol |myprintf|
becomes known inside the BOOT::
package. When we compile
the Aldor code we need to include the package name.
#include "axiom.as"
SI ==> SingleInteger;
arigato():PositiveInteger == { import { BOOT_:_:myprintf: (String) -> SI } from Foreign C; import from SI; BOOT_:_:myprintf("Arigato gozaimasu!"); 1; }
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6328445021691863648-25px002.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. The )library system command was not called after compilation.
Now call it:
arigato()
There are no library operations named arigato Use HyperDoc Browse or issue )what op arigato to learn if there is any operation containing " arigato " in its name.
Cannot find a no-argument definition or library operation named arigato .
Here is a slightly more interesting example that compiles some C language code and calls it from Aldor. Note: clines is a GCL-specific extension
(clines "
/* * nputs.c: A simple C function. */ void nputs(int n,char *s) { int i; for (i = 0; i < n; i++) puts(s); }
")
(defentry |nputs| (int string) (void "nputs"))
; compiling file "/var/aw/var/LatexWiki/6493135638062140292-25px004.lisp" (written 04 APR 2022 08:16:59 PM):
; /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6493135638062140292-25px004.fasl written ; compilation finished in 0:00:00.009
>> System error: The function BOOT::CLINES is undefined.
#include "axiom.as"
SI ==> SingleInteger;
arigato2():PositiveInteger == { import { BOOT_:_:nputs: (SI,String) -> SI } from Foreign C; import from SI; BOOT_:_:nputs(3, "Arigato gozaimasu!"); 1; }
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4532111654619318497-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. The )library system command was not called after compilation.
Now try it:
arigato2()
There are no library operations named arigato2 Use HyperDoc Browse or issue )what op arigato2 to learn if there is any operation containing " arigato2 " in its name.
Cannot find a no-argument definition or library operation named arigato2 .
Here is a simple way to output a string by calling the Lisp function PRINC.
#include "axiom.as"
output(x:String):Void == { import { PRINC: (String) -> Void } from Foreign Lisp; PRINC(x); }
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7406390156942832244-25px007.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. The )library system command was not called after compilation.
Try it.
output("stuff")
stuff