Merge branch 'master' of git://factorcode.org/git/factor

Conflicts:
	basis/compiler/codegen/codegen.factor
db4
Joe Groff 2009-10-01 23:52:26 -05:00
commit 7583b2bfee
3 changed files with 26 additions and 8 deletions

View File

@ -54,14 +54,18 @@ TUPLE: A
: <direct-A> ( alien len -- specialized-array ) A boa ; inline
: <A> ( n -- specialized-array ) [ \ T <underlying> ] keep <direct-A> ; inline
: <A> ( n -- specialized-array )
[ \ T <underlying> ] keep <direct-A> ; inline
: (A) ( n -- specialized-array ) [ \ T (underlying) ] keep <direct-A> ; inline
: (A) ( n -- specialized-array )
[ \ T (underlying) ] keep <direct-A> ; inline
: malloc-A ( len -- specialized-array ) [ \ T heap-size calloc ] keep <direct-A> ; inline
: malloc-A ( len -- specialized-array )
[ \ T heap-size calloc ] keep <direct-A> ; inline
: byte-array>A ( byte-array -- specialized-array )
dup length \ T heap-size /mod 0 = [ drop \ T bad-byte-array-length ] unless
>c-ptr dup length \ T heap-size /mod 0 =
[ drop \ T bad-byte-array-length ] unless
<direct-A> ; inline
M: A clone [ underlying>> clone ] [ length>> ] bi <direct-A> ; inline

View File

@ -276,9 +276,19 @@ HELP: reduce-index
"153"
} } ;
HELP: accumulate-as
{ $values { "identity" object } { "seq" sequence } { "quot" { $quotation "( prev elt -- next )" } } { "exemplar" sequence } { "final" "the final result" } { "newseq" "a new sequence" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of the same type as " { $snippet "exemplar" } " containing intermediate results, together with the final result."
$nl
"The first element of the new sequence is " { $snippet "identity" } ". Then, on the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the old sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the old sequence."
$nl
"When given the empty sequence, outputs an empty sequence together with the " { $snippet "identity" } "." } ;
HELP: accumulate
{ $values { "identity" object } { "seq" sequence } { "quot" { $quotation "( prev elt -- next )" } } { "final" "the final result" } { "newseq" "a new sequence" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results together with the final result. The first element of the new sequence is " { $snippet "identity" } ". Then, on the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the old sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the old sequence."
{ $values { "identity" object } { "seq" sequence } { "quot" { $quotation "( prev elt -- next )" } } { "final" "the final result" } { "newseq" "a new array" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs an array of intermediate results, together with the final result."
$nl
"The first element of the new sequence is " { $snippet "identity" } ". Then, on the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the old sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the old sequence."
$nl
"When given the empty sequence, outputs an empty sequence together with the " { $snippet "identity" } "." }
{ $examples
@ -1400,7 +1410,7 @@ ARTICLE: "sequences-access" "Accessing sequence elements"
ARTICLE: "sequences-add-remove" "Adding and removing sequence elements"
"Adding elements:"
{ $subsections prefix suffix }
{ $subsections prefix suffix insert-nth }
"Removing elements:"
{ $subsections remove remq remove-nth } ;
@ -1495,6 +1505,7 @@ ARTICLE: "sequences-combinators" "Sequence combinators"
map-index
map-reduce
accumulate
accumulate-as
produce
produce-as
}

View File

@ -432,8 +432,11 @@ PRIVATE>
: change-each ( seq quot -- )
over map-into ; inline
: accumulate-as ( seq identity quot exemplar -- final newseq )
[ [ swap ] dip [ curry keep ] curry ] dip map-as ; inline
: accumulate ( seq identity quot -- final newseq )
swapd [ [ call ] [ 2drop ] 3bi ] curry { } map-as ; inline
{ } accumulate-as ; inline
: 2each ( seq1 seq2 quot -- )
(2each) each-integer ; inline