Moving enumerate to sequences-lib.
parent
c6d8362d97
commit
0c030d70ea
|
@ -5,10 +5,6 @@ USING: help.markup help.syntax ;
|
||||||
|
|
||||||
IN: math.finance
|
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
|
HELP: sma
|
||||||
{ $values { "seq" "a sequence" } { "n" "number of periods" } { "newseq" "a sequence" } }
|
{ $values { "seq" "a sequence" } { "n" "number of periods" } { "newseq" "a sequence" } }
|
||||||
{ $description "Returns the Simple Moving Average with the specified periodicity." } ;
|
{ $description "Returns the Simple Moving Average with the specified periodicity." } ;
|
||||||
|
|
|
@ -6,9 +6,6 @@ math math.functions math.statistics math.vectors ;
|
||||||
|
|
||||||
IN: math.finance
|
IN: math.finance
|
||||||
|
|
||||||
: enumerate ( seq -- newseq )
|
|
||||||
<enum> >alist ;
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: weighted ( x y a -- z )
|
: weighted ( x y a -- z )
|
||||||
|
@ -17,13 +14,10 @@ IN: math.finance
|
||||||
: a ( n -- a )
|
: a ( n -- a )
|
||||||
1 + 2 swap / ;
|
1 + 2 swap / ;
|
||||||
|
|
||||||
: first-rest ( seq -- first rest )
|
|
||||||
[ first ] keep 1 tail-slice ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: ema ( seq n -- newseq )
|
: 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 )
|
: sma ( seq n -- newseq )
|
||||||
clump [ mean ] map ;
|
clump [ mean ] map ;
|
||||||
|
|
|
@ -23,3 +23,7 @@ HELP: randomize
|
||||||
{ $values { "seq" sequence } { "seq'" sequence } }
|
{ $values { "seq" sequence } { "seq'" sequence } }
|
||||||
{ $description "Shuffle the elements in the sequence randomly, returning the new 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 }" } ;
|
||||||
|
|
||||||
|
|
|
@ -60,3 +60,6 @@ IN: sequences.lib.tests
|
||||||
[ 1 2 { 3 4 } [ + + drop ] 2 each-withn ] must-infer
|
[ 1 2 { 3 4 } [ + + drop ] 2 each-withn ] must-infer
|
||||||
{ 13 } [ 1 2 { 3 4 } [ + + ] 2 each-withn + ] unit-test
|
{ 13 } [ 1 2 { 3 4 } [ + + ] 2 each-withn + ] unit-test
|
||||||
[ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
|
[ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
|
||||||
|
|
||||||
|
[ { { 0 1 } { 1 2 } { 2 3 } } ] [ { 1 2 3 } enumerate ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -168,3 +168,9 @@ USE: random
|
||||||
: randomize ( seq -- seq' )
|
: randomize ( seq -- seq' )
|
||||||
dup length 1 (a,b] [ dup random pick exchange ] each ;
|
dup length 1 (a,b] [ dup random pick exchange ] each ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: enumerate ( seq -- seq' )
|
||||||
|
<enum> >alist ;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue