RosettaCodeData/Task/Reverse-words-in-a-string/OCaml/reverse-words-in-a-string.ocaml
2015-02-20 09:02:09 -05:00

16 lines
553 B
Text

#load "str.cma"
let input = ["---------- Ice and Fire ------------";
"";
"fire, in end will world the say Some";
"ice. in say Some";
"desire of tasted I've what From";
"fire. favor who those with hold I";
"";
"... elided paragraph last ...";
"";
"Frost Robert -----------------------"];;
let splitted = List.map (Str.split (Str.regexp " ")) input in
let reversed = List.map List.rev splitted in
let final = List.map (String.concat " ") reversed in
List.iter print_endline final;;