ListWithEllipsis.as

View: New views
1 Messages — Rating Filter:   Alert me  

ListWithEllipsis.as

by Ralf Hemmecke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some unuseful code to allow  mylist := [1,3..15] to work.

 >aldor -grun -lalgebra -laldor ListWithEllipsis.as
[1,2..10] = [1,2,3,4,5,6,7,8,9,10]
[1,3..11] = [1,3,5,7,9,11]
[1,2+2*x..5+8*x] = [1,2*x + 2,4*x + 3,6*x + 4,8*x + 5]

Ralf

---BEGIN ListWithEllipsis.as
#include "algebra"
#include "aldorio"
Range(T: AbelianGroup): with {
        left: % -> T;
        right: % -> T;
        ..: (T, T) -> %;
        bounds: % -> (T, T);
} == add {
        Rep == Record(a: T, b: T);
        import from Rep;
        left(x: %): T == rep(x).a;
        right(x: %): T == rep(x).b;
        (l: T) .. (r: T): % == per [l, r];
        bounds(x: %): (T, T) == explode rep x;
}
extend List(T: AbelianGroup): with {
        bracket: (T, Range T) -> %;
} == add {
        listElements(start: T, end: T, step: T): Generator T == generate {
                yield x := start;
                while not (x = end) repeat yield x := x + step;
        }
        bracket(t: T, range: Range T): % == {
                (l, r) := bounds range;
                [x for x in listElements(t, r, l-t)];
        }
}
main(): () == {
        import from Integer, Range Integer, Symbol;
        li: List Integer := [1,2..10];
        stdout << "[1,2..10] = " << li << newline;
        li: List Integer := [1,3..11];
        stdout << "[1,3..11] = " << li << newline;

        P ==> SparseUnivariatePolynomial(Integer, -"x");
        import from P, Range P;
        x: P := monom;
        e: P := 1;
        lp: List P := [e, 2*e+2*x .. 5*e+8*x];
        stdout << "[1,2+2*x..5+8*x] = " << lp << newline;
}
main();
---END ListWithEllipsis.as

_______________________________________________
Aldor-l mailing list
Aldor-l@...
http://aldor.org/mailman/listinfo/aldor-l_aldor.org