2 USING: help.markup help.syntax sequences hashtables quotations assocs ;
\r
7 { "hashtable" hashtable }
\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
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
20 { "hashtable" hashtable } { "seq" sequence }
\r
21 { "hashtable" hashtable }
\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
30 { $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
\r
32 HELP: sequence>assoc
\r
34 { "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
\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
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
46 HELP: sequence>assoc*
\r
48 { "assoc" assoc } { "seq" sequence } { "quot" quotation }
\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
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
60 HELP: sequence>hashtable
\r
62 { "seq" sequence } { "quot" quotation }
\r
63 { "hashtable" hashtable }
\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
72 { $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;
\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