The entire time I was reading, I hoped that a Haskell solution would be there (knowing it would be much simpler), I got my wish :) +1 to haskell
import Data.List
main = putStr . unlines . filter ("ing" `isSuffixOf`) . words =<< getContents
(To be read from right to left.)A Forth example would be interesting.
: print-ing ( filepath encoding -- )
[ [
" " split
[ dup "ing" tail? [ print ] [ drop ] if ] each ]
each-line ]
with-file-reader ;
It's kind of ugly because it's designed to print out the values without leaving anything on the stack. It can be prettier if it produces an array of matching words : collect-ing ( filepath encoding -- seq ) { } -rot
[ [
" " split
[ "ing" tail? ] filter append ]
each-line ]
with-file-reader ;
and then just prints that out : print-ing ( filepath encoding -- )
collect-ing [ print ] each ;