sequences: implement sum on iota-tuple.
parent
fe45a08054
commit
71ad332027
|
@ -283,7 +283,7 @@ unit-test
|
||||||
[ { "d" "a" "b" "c" } ] [ { 3 0 1 2 } { "a" "b" "c" "d" } nths ] unit-test
|
[ { "d" "a" "b" "c" } ] [ { 3 0 1 2 } { "a" "b" "c" "d" } nths ] unit-test
|
||||||
|
|
||||||
[ "dac" ] [ { 3 0 2 } "abcd" nths ] unit-test
|
[ "dac" ] [ { 3 0 2 } "abcd" nths ] unit-test
|
||||||
|
|
||||||
TUPLE: bogus-hashcode ;
|
TUPLE: bogus-hashcode ;
|
||||||
|
|
||||||
M: bogus-hashcode hashcode* 2drop 0 >bignum ;
|
M: bogus-hashcode hashcode* 2drop 0 >bignum ;
|
||||||
|
@ -316,6 +316,10 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
|
||||||
[ -1 iota ] must-fail
|
[ -1 iota ] must-fail
|
||||||
[ T{ iota-tuple { n 10 } } ] [ 10 iota ] unit-test
|
[ T{ iota-tuple { n 10 } } ] [ 10 iota ] unit-test
|
||||||
[ 0 ] [ 10 iota first ] unit-test
|
[ 0 ] [ 10 iota first ] unit-test
|
||||||
|
{ 0 } [ 0 iota sum ] unit-test
|
||||||
|
{ 1 } [ 1 iota sum ] unit-test
|
||||||
|
{ 10 } [ 5 iota sum ] unit-test
|
||||||
|
{ 15 } [ 6 iota sum ] unit-test
|
||||||
|
|
||||||
[ "hi" 3 ] [
|
[ "hi" 3 ] [
|
||||||
{ 1 2 3 4 5 6 7 8 } [ H{ { 3 "hi" } } at ] map-find
|
{ 1 2 3 4 5 6 7 8 } [ H{ { 3 "hi" } } at ] map-find
|
||||||
|
|
|
@ -1006,6 +1006,7 @@ PRIVATE>
|
||||||
|
|
||||||
GENERIC: sum ( seq -- n )
|
GENERIC: sum ( seq -- n )
|
||||||
M: object sum 0 [ + ] binary-reduce ; inline
|
M: object sum 0 [ + ] binary-reduce ; inline
|
||||||
|
M: iota-tuple sum length dup 1 - * 2/ ; inline
|
||||||
|
|
||||||
: product ( seq -- n ) 1 [ * ] binary-reduce ;
|
: product ( seq -- n ) 1 [ * ] binary-reduce ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue