From 4977d4a224614e633b6c06d78e8112d2d95809dc Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 3 Jul 2008 12:25:51 -0500 Subject: [PATCH] sequences-docs: sigma and count --- core/sequences/sequences-docs.factor | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 86a2aa12f6..253d403d23 100755 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -957,3 +957,23 @@ HELP: unfold "The " { $snippet "tail" } " quotation is used when the predicate produces more than one output value. In this case, we have to drop this value even if the predicate fails in order for stack inference to calculate a stack effect for the " { $link unfold } " call:" { $unchecked-example "USING: kernel prettyprint random sequences ;" "[ 10 random dup 1 > ] [ ] [ drop ] unfold ." "{ 8 2 2 9 }" } } ; + +HELP: sigma +{ $values { "seq" sequence } { "quot" quotation } { "n" number } } +{ $description "Like map sum, but without creating an intermediate sequence." } +{ $example + "! Find the sum of the squares [0,99]" + "USING: math math.ranges sequences.lib prettyprint ;" + "100 [1,b] [ sq ] sigma ." + "338350" +} ; + +HELP: count +{ $values { "seq" sequence } { "quot" quotation } { "n" integer } } +{ $description "Efficiently returns the number of elements that the predicate quotation matches." } +{ $example + "USING: math math.ranges sequences.lib prettyprint ;" + "100 [1,b] [ even? ] count ." + "50" +} ; +