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

On Wednesday, May 31, 2006 2:54 AM Gernot Hueber wrote:

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:

lisp
(defentry |myprintf| (string) (int "printf"))
lisp
; compiling file "/var/aw/var/LatexWiki/8624266922497102717-25px001.lisp" (written 14 JUL 2013 10:41:18 AM):
; /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/8624266922497102717-25px001.fasl written ; compilation finished in 0:00:00.002
>> 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.

aldor
#include "axiom.as"
SI ==> SingleInteger;
arigato():PositiveInteger == { import { BOOT_:_:myprintf: (String) -> SI } from Foreign C; import from SI; BOOT_:_:myprintf("Arigato gozaimasu!"); 1; }
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6328445021691863648-25px002.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/6328445021691863648-25px002.as", line 5: arigato():PositiveInteger == { ^.........^ [L5 C1] #10 (Error) There are no suitable meanings for the operator `->'. [L5 C11] #9 (Error) No meaning for identifier `PositiveInteger'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6328445021691863648-25px002.as", line 6: import { BOOT_:_:myprintf: (String) -> SI } from Foreign C; ............................^ [L6 C29] #12 (Error) No meaning for identifier `String'. [L6 C29] #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.

Now call it:

fricas
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

lisp
(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"))
lisp
; compiling file "/var/aw/var/LatexWiki/6493135638062140292-25px004.lisp" (written 14 JUL 2013 10:41:18 AM):
; /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6493135638062140292-25px004.fasl written ; compilation finished in 0:00:00.001
>> System error: The function BOOT::CLINES is undefined.

aldor
#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; }
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4532111654619318497-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/4532111654619318497-25px005.as", line 3: SI ==> SingleInteger; .......^ [L3 C8] #12 (Error) (After Macro Expansion) No meaning for identifier `SingleInteger'. Expanded expression was: SingleInteger
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4532111654619318497-25px005.as", line 5: arigato2():PositiveInteger == { ^..........^ [L5 C1] #10 (Error) There are no suitable meanings for the operator `->'. [L5 C12] #9 (Error) No meaning for identifier `PositiveInteger'. [L5 C12] #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.

Now try it:

fricas
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.

aldor
#include "axiom.as"
output(x:String):Void == { import { PRINC: (String) -> Void } from Foreign Lisp; PRINC(x); }
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7406390156942832244-25px007.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/7406390156942832244-25px007.as", line 3: output(x:String):Void == { .......^.^.......^ [L3 C8] #11 (Error) There are no suitable meanings for the operator `->'. [L3 C10] #9 (Error) No meaning for identifier `String'. [L3 C18] #10 (Error) No meaning for identifier `Void'. [L3 C18] #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.

Try it.

fricas
output("stuff")
stuff
Type: Void




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: