! takes a sequence of items, adds the different items to a hash as keys and does something to the value, either based on the item or unconditionally. ! if the key repeats, the value will change again. : (change-at) ( key assoc quot init -- ) ! applies quot or init [ 2dup at* ] 2dip '[ [ @ ] [ drop _ ] if ] call -rot set-at ; :: summarize ( sequence quot/cond initial-value -- hash ) H{ } clone :> the-hash quot/cond quotation? [ [ nip ] ] [ [ cond ] ] if :> nip/cond sequence [ the-hash ! key assoc over quot/cond nip/cond call ! key assoc quot initial-value (change-at) ] each the-hash ; ! btw, what is a better way to thread the hash thru the code without using global vars or locals? ! example words which use summarize : count-all ( seq -- hash ) [ 1 + ] 1 summarize ; ! { 1 2 3 4 4 6 7 } => H{ { 1 1 } { 2 1 } { 3 1 } { 4 2 } { 6 1 } { 7 1 } } : a-them ( seq -- hash ) [ "a" append ] "" summarize ; ! { 1 2 3 4 4 6 7 } => H{ { 1 "" } { 2 "" } { 3 "" } { 4 "a" } { 6 "" } { 7 "" } } ! example conditions : conditions ( -- seq-of-quot ) ! must output a quot { { [ dup even? ] [ drop [ 2 + ] ] } { [ dup odd? ] [ drop [ 1 + ] ] } [ "huh?" throw ] } ; : x-all ( seq -- hash ) conditions 2 summarize ; ! { 1 2 3 4 4 6 7 } => H{ { 1 2 } { 2 2 } { 3 2 } { 4 4 } { 6 2 } { 7 2 } } ! surely there is already an idiomatic/built-in way to do this ... if u know leave a comment or tell me on irc. thanks