Paste: lazy arrays

Author: rien
Mode: factor
Date: Sat, 31 Dec 2011 23:47:50
Plain Text |
IN: scratchpad V{ } 0 [ 96 + 1 swap <string> "@1" append ] <lazy-seq>

--- Data stack:
T{ lazy-seq f ~vector~ 0 ~quotation~ }
IN: scratchpad [ { [ 1 swap nth ] [ 2 swap nth ] [ 3 swap nth ] } cleave ] keep

--- Data stack:
"a@1"
"b@1"
"c@1"
T{ lazy-seq f ~vector~ 0 ~quotation~ }
IN: scratchpad [ [ len>> ] [ seq>> ] bi ] keep

--- Data stack:
"a@1"
"b@1"
"c@1"
0
V{ 0 "a@1" "b@1" "c@1" }
T{ lazy-seq f ~vector~ 0 ~quotation~ }

Annotation: not-yet-ready code for lazy arrays

Author: rien
Mode: factor
Date: Sun, 1 Jan 2012 00:03:07
Plain Text |
USING: accessors kernel locals math sequences ;
IN: lazy-seqs


TUPLE: lazy-seq seq len quot ;

INSTANCE: lazy-seq sequence


:: lazy-seq-nth ( n lseq -- elt )
    ! simply nth if length includes n
    lseq len>> n >= [ n lseq seq>> nth ] [
        n lseq quot>> call( x -- x ) :> new-elt
        new-elt n lseq set-nth
        new-elt
    ] if ;


M: lazy-seq length len>> ;
M: lazy-seq nth lazy-seq-nth ;
M: lazy-seq set-nth seq>> set-nth ;


C: <lazy-seq> lazy-seq


V{ } 0 [ 96 + 1 swap <string> "@1" append ] <lazy-seq>

New Annotation

Summary:
Author:
Mode:
Body: