]> gitweb.factorcode.org Git - factor.git/blob - extra/histogram/histogram-docs.factor
0c4059fa596bb9c347c7e4337fcd2bec3b5be156
[factor.git] / extra / histogram / histogram-docs.factor
1 IN: histogram\r
2 USING: help.markup help.syntax sequences hashtables quotations assocs ;\r
3 \r
4 HELP: histogram\r
5 { $values\r
6     { "seq" sequence }\r
7     { "hashtable" hashtable }\r
8 }\r
9 { $examples \r
10     { $example "! Count the number of times an element appears in a sequence."\r
11                "USING: prettyprint histogram ;"\r
12                "\"aaabc\" histogram ."\r
13                "H{ { 97 3 } { 98 1 } { 99 1 } }"\r
14     }\r
15 }\r
16 { $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." } ;\r
17 \r
18 HELP: histogram*\r
19 { $values\r
20     { "hashtable" hashtable } { "seq" sequence }\r
21     { "hashtable" hashtable }\r
22 }\r
23 { $examples \r
24     { $example "! Count the number of times the elements of two sequences appear."\r
25                "USING: prettyprint histogram ;"\r
26                "\"aaabc\" histogram \"aaaaaabc\" histogram* ."\r
27                "H{ { 97 9 } { 98 2 } { 99 2 } }"\r
28     }\r
29 }\r
30 { $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;\r
31 \r
32 HELP: sequence>assoc\r
33 { $values\r
34     { "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }\r
35     { "assoc" assoc }\r
36 }\r
37 { $examples \r
38     { $example "! Iterate over a sequence and increment the count at each element"\r
39                "USING: assocs prettyprint histogram ;"\r
40                "\"aaabc\" [ inc-at ] H{ } sequence>assoc ."\r
41                "H{ { 97 3 } { 98 1 } { 99 1 } }"\r
42     }\r
43 }\r
44 { $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." } ;\r
45 \r
46 HELP: sequence>assoc*\r
47 { $values\r
48     { "assoc" assoc } { "seq" sequence } { "quot" quotation }\r
49     { "assoc" assoc }\r
50 }\r
51 { $examples \r
52     { $example "! Iterate over a sequence and add the counts to an existing assoc"\r
53                "USING: assocs prettyprint histogram kernel ;"\r
54                "H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc* ."\r
55                "H{ { 97 5 } { 98 2 } { 99 1 } }"\r
56     }\r
57 }\r
58 { $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." } ;\r
59 \r
60 HELP: sequence>hashtable\r
61 { $values\r
62     { "seq" sequence } { "quot" quotation }\r
63     { "hashtable" hashtable }\r
64 }\r
65 { $examples \r
66     { $example "! Count the number of times an element occurs in a sequence"\r
67                "USING: assocs prettyprint histogram ;"\r
68                "\"aaabc\" [ inc-at ] sequence>hashtable ."\r
69                "H{ { 97 3 } { 98 1 } { 99 1 } }"\r
70     }\r
71 }\r
72 { $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;\r
73 \r
74 ARTICLE: "histogram" "Computing histograms"\r
75 "Counting elements in a sequence:"\r
76 { $subsection histogram }\r
77 { $subsection histogram* }\r
78 "Combinators for implementing histogram:"\r
79 { $subsection sequence>assoc }\r
80 { $subsection sequence>assoc* }\r
81 { $subsection sequence>hashtable } ;\r
82 \r
83 ABOUT: "histogram"\r