axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] aldor stream oddities


From: Martin Rubey
Subject: Re: [Axiom-developer] aldor stream oddities
Date: 09 Aug 2007 17:34:34 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Franz Lehner <address@hidden> writes:

> is there a way to get hold of generate$Stream using the aldor compiler?

Not easily, because:

> I spent quite some time until figuring out that generate is probably
> a keyword in aldor 

yes it is.

I wrote the following hack to be able to coerce Aldor generators to Axiom
Streams. Maybe this is of help.

What the thing below really does is to make "delay" available to Aldor, only
under a different name, because delay is a keyword in Aldor, too, I think.

--combinat/src/examples.as-------------------------------------------------

The following makes generators coercible to streams in \xAxiom.  Be warned,
however, that the coercion steps the generator.

<<ext: Generator>>=
extend Generator(S:Type): with {
        CoercibleTo Stream S;
} == add {
        <<get the magic NonNullStream symbol>>
        myDelay(f: () -> Stream S): Stream S == {
                [NonNullStream, f pretend Stream S]$REC pretend Stream S;
        }
        coerce(x: %): Stream S == {
                aux(): Stream S == {
                        import from Partial S;
                        n := partialNext! x pretend Partial S; 
                        if failed?(n)$Partial(S)
                        then empty()
                        else cons(retract(n)$Partial(S), myDelay aux);
                }
                myDelay(aux);
        }
}
@

The following piece of code fetches the magic \adcode|NonNullStream| symbol
used in \xAxiom{} to indicate a lazy stream.  As we can see in
stream.spad.pamphlet, a lazy stream is represented as follows:
\begin{adsnippet}
    NullStream:    S := _$NullStream$Lisp    pretend S
    Rep := Record(firstElt: S, restOfStream: %)
    delay(fs:()->%) == [NonNullStream, fs pretend %]
\end{adsnippet}

Unfortunately, the \adcode|delay| function is not available via libaxiom, so we
have to provide our own.  The only tricky part is to get hold of the lisp
symbol \adcode|$NullStream$Lisp|.  We are in luck however, since the libaxiom
exports a lazy stream via \adcode|integers$StreamTaylorSeriesOperations|.  More
precisely, its first element is non-lazy, but the second is.

<<get the magic NonNullStream symbol>>=
        import from Integer, StreamTaylorSeriesOperations Integer;
        import from Stream Integer;
        REC == Record(firstElt: S, restOfStream: Stream S);
        import from REC;
        NonNullStream: S := ((rst integers 0) pretend REC).firstElt;
@





reply via email to

[Prev in Thread] Current Thread [Next in Thread]