Squeak Smalltalk で書いてみた。

| bag |
bag := Bag new.
FileStream fileNamed: 'sample.txt' do: [:file |
  [file atEnd] whileFalse: [bag addAll: (file nextLine subStrings: ' ')]
].
^bag valuesAndCounts