2 ms·
> pascal didn't actually come with a batteries included piping concept No, it has function calls instead. > I think the shell script version would have been m
by lisper 11y ago
> pascal didn't actually come with a batteries included piping concept
No, it has function calls instead.
> I think the shell script version would have been multicore friendly
Not unless 'sort' is implemented very cleverly.
> maybe Knuth's version
We'll never know unless someone manages to dredge up the source code.
But the specifics on Knuth's version are not really the point. Someone else might have been able to do better. And someone using a less brain damaged language that Pascal might have been able to do even better. In fact, here it is in four lines of Common Lisp (using Ergolib - https://github.com/rongarret/ergolib https://github.com/rongarret/ergolib):
(defun histogram (path)
(bb l (split (file-contents path) t :test (fn (a b) (whitespacep b)))
l (sort 'string< (mapcar 'string-upcase (remove "" l)))
(for item in (remove-duplicates l) collect (list item (count item l)))))
Writing a pure CL version is left as an exercise. My guess is it would be 10-20 LOC.