Moving enumerate to sequences-lib.

db4
John Benediktsson 2008-09-25 21:25:27 -07:00
parent c6d8362d97
commit 0c030d70ea
5 changed files with 14 additions and 11 deletions

View File

@ -5,10 +5,6 @@ USING: help.markup help.syntax ;
IN: math.finance
HELP: enumerate
{ $values { "seq" "a sequence" } { "newseq" "a sequence" } }
{ $description "Returns a new sequence where each element is an array of { value, index }" } ;
HELP: sma
{ $values { "seq" "a sequence" } { "n" "number of periods" } { "newseq" "a sequence" } }
{ $description "Returns the Simple Moving Average with the specified periodicity." } ;

View File

@ -6,9 +6,6 @@ math math.functions math.statistics math.vectors ;
IN: math.finance
: enumerate ( seq -- newseq )
<enum> >alist ;
<PRIVATE
: weighted ( x y a -- z )
@ -17,13 +14,10 @@ IN: math.finance
: a ( n -- a )
1 + 2 swap / ;
: first-rest ( seq -- first rest )
[ first ] keep 1 tail-slice ;
PRIVATE>
: ema ( seq n -- newseq )
a swap first-rest swap [ [ dup ] 2dip swap rot weighted ] accumulate 2nip ;
a swap unclip [ [ dup ] 2dip swap rot weighted ] accumulate 2nip ;
: sma ( seq n -- newseq )
clump [ mean ] map ;

View File

@ -23,3 +23,7 @@ HELP: randomize
{ $values { "seq" sequence } { "seq'" sequence } }
{ $description "Shuffle the elements in the sequence randomly, returning the new sequence." } ;
HELP: enumerate
{ $values { "seq" sequence } { "seq'" sequence } }
{ $description "Returns a new sequence where each element is an array of { index, value }" } ;

View File

@ -60,3 +60,6 @@ IN: sequences.lib.tests
[ 1 2 { 3 4 } [ + + drop ] 2 each-withn ] must-infer
{ 13 } [ 1 2 { 3 4 } [ + + ] 2 each-withn + ] unit-test
[ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
[ { { 0 1 } { 1 2 } { 2 3 } } ] [ { 1 2 3 } enumerate ] unit-test

View File

@ -168,3 +168,9 @@ USE: random
: randomize ( seq -- seq' )
dup length 1 (a,b] [ dup random pick exchange ] each ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: enumerate ( seq -- seq' )
<enum> >alist ;