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

Edit detail for SandBox Aldor Generator revision 1 of 3

1 2 3
Editor: 127.0.0.1
Time: 2007/11/11 11:32:05 GMT-8
Note: transferred from axiom-developer

changed:
-
Aldor has generators:

http://www.aldor.org/docs/HTML/chap9.html --
In fact, this form of using generators is so common, that
if the expression E in 'for v in E.' does not belong to a
generator type, then an implicit call is made to an appropriate
generator function. This is equivalent to writing
'for v in generator E.'

The Aldor/Axiom interface provides such a generator for the
Axiom Vector type. Let's try it.

**More space?** I am not sure why but it seems that I must
increase GCL memory allocation to make this work.
\begin{axiom}
)lisp (si::allocate-contiguous-pages 1500 t)
)lisp (si::allocate 'sfun 50 t)
\end{axiom}

\begin{aldor}
#include "axiom"

myList(v:Vector Integer):List Integer == [ i for i in v ];
\end{aldor}

\begin{axiom}
V:Vector Integer:=[1,2,3]
myList(V)
\end{axiom}
Space left?
\begin{axiom}
)lisp (room)
\end{axiom}


From BillPage Thu Aug 9 10:53:09 -0500 2007
From: Bill Page
Date: Thu, 09 Aug 2007 10:53:09 -0500
Subject: Re: aldor stream oddities
Message-ID: <20070809105309-0500@wiki.axiom-developer.org>

**On Aug 9, 2007 10:07 AM Franz Lehner wrote:**

Hello,

is there a way to get hold of 'generate$Stream' using the aldor compiler?
I spent quite some time until figuring out that generate is probably
a keyword in aldor (I could not check as the aldor site seems to be down)
and this causes strange error messages.
The following two snippets do not work, note that the second leads to a
segfault::

  =================================================
  #include "axiom"
  
  teststream: with {
         zerostream:()->Stream Integer;
  } == add {
         zerostream():Stream Integer == {
                 import from Integer;
                 generate((x:Integer):Integer +-> 0@Integer,0@Integer);
  }
  }
  =================================================
  aldor -Fasy -Fao -Flsp  -laxiom -DAxiom -Y/home/lehner/usr/local/lib/wh-sandbox_s1/target/x86_64-unknown-linux/algebra test1.as "test1.as", line 8:
                   generate((x:Integer):Integer +-> 0@Integer,0@Integer);
  .........................^
  [L8 C26] #1 (Error) Have determined 1 possible types for the expression.
           Meaning 1: (x: Integer) -> Integer, Integer
     The context requires an expression of type Stream(Integer).

  make: *** [test.ao] Fehler 1

  =========================================================
  #include "axiom"

  teststream: with {
         zerostream:()->Stream Integer;
  } == add {
         zerostream():Stream Integer == {
                 import from Integer;
                 generate(():Integer +-> 0@Integer);
  }
  }
  =========================================================
  aldor -Fasy -Fao -Flsp  -laxiom -DAxiom -Y/home/lehner/usr/local/lib/wh-sandbox_s1/target/x86_64-unknown-linux/algebra est2.as
  Program fault (segmentation violation).#3 (Error) Program fault
  (segmentation violation).
  "test2.as", line 6:         zerostream():Stream Integer == {
                      .......................................^
  [L6 C40] #1 (Error) Have determined 0 possible types for the expression.
     Subexpression `import from Integer':
           Meaning 1: (0 types)

  "test.as", line 9:                 generate(():Integer +-> 0@Integer);
                      .........................^
  [L9 C26] #2 (Error) Have determined 0 possible types for the expression.

  make: *** [test.ao] Fehler 1

** Bill Page replied:**

Here is one way. The important thing is to escape the keyword
'generator' by prefix with '_'.

\begin{aldor}
#include "axiom"

teststream: with {
        zerostream:()->Stream Integer;
} == add {
        zerostream():Stream Integer == {
                import from Integer;
                _generate((x:Integer):Integer +-> 0@Integer,0@Integer);
}
}
\end{aldor}

\begin{axiom}
zerostream()
\end{axiom}


Aldor has generators:

http://www.aldor.org/docs/HTML/chap9.html
In fact, this form of using generators is so common, that if the expression E in for v in E. does not belong to a generator type, then an implicit call is made to an appropriate generator function. This is equivalent to writing for v in generator E.

The Aldor/Axiom interface provides such a generator for the Axiom Vector type. Let's try it.

More space? I am not sure why but it seems that I must increase GCL memory allocation to make this work.

axiom
)lisp (si::allocate-contiguous-pages 1500 t)
Value = T
axiom
)lisp (si::allocate 'sfun 50 t)
Value = T

aldor
#include "axiom"
myList(v:Vector Integer):List Integer == [ i for i in v ];
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/4218486668628728926-25px002.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./4218486668628728926-25px002.lsp
   Issuing )library command for 4218486668628728926-25px002
   Reading /var/zope2/var/LatexWiki/4218486668628728926-25px002.asy

axiom
V:Vector Integer:=[1,2,3]
LatexWiki Image(1)
Type: Vector Integer
axiom
myList(V)
LatexWiki Image(2)
Type: List Integer

Space left?

axiom
)lisp (room)
1766/2326 100.0% 1 CONS BIGNUM RATIO COMPLEX STRUCTURE 108/200 71.9% FIXNUM SHORT-FLOAT LONG-FLOAT CHARACTER RANDOM-STATE READTABLE SPICE 612/795 99.9% 1 SYMBOL STREAM PATHNAME CCLOSURE CLOSURE 1/8 34.8% PACKAGE 27/400 53.4% ARRAY HASH-TABLE VECTOR BIT-VECTOR 55/100 99.0% CFUN CFDATA 643/643 72.8% 3 SFUN STRING GFUN VFUN AFUN
2612/2856 2 contiguous (392 blocks) 1320 hole 2315 71.5% 5 relocatable
3212 pages for cells 9459 total pages 237919 pages available 14766 pages in heap but not gc'd + pages needed for gc marking 262144 maximum pages Value = NIL

Re: aldor stream oddities --Bill Page, Thu, 09 Aug 2007 10:53:09 -0500 reply
On Aug 9, 2007 10:07 AM Franz Lehner wrote:

Hello,

is there a way to get hold of generate$Stream using the aldor compiler? I spent quite some time until figuring out that generate is probably a keyword in aldor (I could not check as the aldor site seems to be down) and this causes strange error messages. The following two snippets do not work, note that the second leads to a segfault:

  =================================================
  #include "axiom"

  teststream: with {
         zerostream:()->Stream Integer;
  } == add {
         zerostream():Stream Integer == {
                 import from Integer;
                 generate((x:Integer):Integer +-> 0@Integer,0@Integer);
  }
  }
  =================================================
  aldor -Fasy -Fao -Flsp  -laxiom -DAxiom -Y/home/lehner/usr/local/lib/wh-sandbox_s1/target/x86_64-unknown-linux/algebra test1.as "test1.as", line 8:
                   generate((x:Integer):Integer +-> 0@Integer,0@Integer);
  .........................^
  [L8 C26] #1 (Error) Have determined 1 possible types for the expression.
           Meaning 1: (x: Integer) -> Integer, Integer
     The context requires an expression of type Stream(Integer).

  make: *** [test.ao] Fehler 1

  =========================================================
  #include "axiom"

  teststream: with {
         zerostream:()->Stream Integer;
  } == add {
         zerostream():Stream Integer == {
                 import from Integer;
                 generate(():Integer +-> 0@Integer);
  }
  }
  =========================================================
  aldor -Fasy -Fao -Flsp  -laxiom -DAxiom -Y/home/lehner/usr/local/lib/wh-sandbox_s1/target/x86_64-unknown-linux/algebra est2.as
  Program fault (segmentation violation).#3 (Error) Program fault
  (segmentation violation).
  "test2.as", line 6:         zerostream():Stream Integer == {
                      .......................................^
  [L6 C40] #1 (Error) Have determined 0 possible types for the expression.
     Subexpression `import from Integer':
           Meaning 1: (0 types)

  "test.as", line 9:                 generate(():Integer +-> 0@Integer);
                      .........................^
  [L9 C26] #2 (Error) Have determined 0 possible types for the expression.

  make: *** [test.ao] Fehler 1

Bill Page replied:

Here is one way. The important thing is to escape the keyword generator by prefix with _.

aldor
#include "axiom"
teststream: with { zerostream:()->Stream Integer; } == add { zerostream():Stream Integer == { import from Integer; _generate((x:Integer):Integer +-> 0@Integer,0@Integer); } }
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/5904224867308724363-25px005.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./5904224867308724363-25px005.lsp
   Issuing )library command for 5904224867308724363-25px005
   Reading /var/zope2/var/LatexWiki/5904224867308724363-25px005.asy
   teststream is now explicitly exposed in frame initial 
   teststream will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/5904224867308724363-25px005

axiom
zerostream()
LatexWiki Image(3)
Type: Stream Integer