From feee2508313d1ee44cefd0b329baadeb824fcb2a Mon Sep 17 00:00:00 2001 From: Auberon Lopez Date: Sun, 17 May 2026 16:28:11 -0700 Subject: [PATCH 1/3] Add File Input Output In OCaml --- archive/o/ocaml/file-input-output.ml | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 archive/o/ocaml/file-input-output.ml diff --git a/archive/o/ocaml/file-input-output.ml b/archive/o/ocaml/file-input-output.ml new file mode 100644 index 000000000..a0b3229bb --- /dev/null +++ b/archive/o/ocaml/file-input-output.ml @@ -0,0 +1,33 @@ +let filename = "output.txt" + +(* Some arbitrary interesting text for demo file reading and writing. + These are the 10 thunderwords from Joyce's Finnegans Wake. + See here for a great literary explanation if you're interested: + https://hatterscabinet.com/pages-fw/fwtheme-thunderwords.html *) +let sample_text = + {|bababadalgharaghtakamminarronnkonnbronntonnerronntuonnthunntrovarrhounawnskawntoohoohoordenenthurnuk +Perkodhuskurunbarggruauyagokgorlayorgromgremmitghundhurthrumathunaradidillifaititillibumullunukkunun +klikkaklakkaklaskaklopatzklatschabattacreppycrottygraddaghsemmihsammihnouithappluddyappladdypkonpkot +Bladyughfoulmoecklenburgwhurawhorascortastrumpapornanennykocksapastippatappatupperstrippuckputtanach +Thingcrooklyexineverypasturesixdixlikencehimaroundhersthemaggerbykinkinkankanwithdownmindlookingated +Lukkedoerendunandurraskewdylooshoofermoyportertooryzooysphalnabortansporthaokansakroidverjkapakkapuk +Bothallchoractorschumminaroundgansumuminarumdrumstrumtruminahumptadumpwaultopoofoolooderamaunsturnup +Pappappapparrassannuaragheallachnatullaghmonganmacmacmacwhackfalltherdebblenonthedubblandaddydoodled +husstenhasstencaffincoffintussemtossemdamandamnacosaghcusaghhobixhatouxpeswchbechoscashlcarcarcaract +Ullhodturdenweirmudgaardgringnirurdrmolnirfenrirlukkilokkibaugimandodrrerinsurtkrinmgernrackinarockar +|} + +let () = + (try + Out_channel.with_open_text filename (fun oc -> + Out_channel.output_string oc sample_text) + with Sys_error msg -> + Printf.eprintf "Failed to write to '%s': %s\n" filename msg; + exit 1); + + try + In_channel.with_open_text filename (fun ic -> In_channel.input_lines ic) + |> List.iter print_endline + with Sys_error msg -> + Printf.eprintf "Failed to read from '%s': %s\n" filename msg; + exit 1 From f2a65e94c322bf574f8f0e7ded3a5dd20bd2dfc6 Mon Sep 17 00:00:00 2001 From: Auberon Lopez Date: Sun, 17 May 2026 16:36:07 -0700 Subject: [PATCH 2/3] OCaml File IO: moved printing logic out of file-reading try block --- archive/o/ocaml/file-input-output.ml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/archive/o/ocaml/file-input-output.ml b/archive/o/ocaml/file-input-output.ml index a0b3229bb..4b57abd27 100644 --- a/archive/o/ocaml/file-input-output.ml +++ b/archive/o/ocaml/file-input-output.ml @@ -25,9 +25,8 @@ let () = Printf.eprintf "Failed to write to '%s': %s\n" filename msg; exit 1); - try - In_channel.with_open_text filename (fun ic -> In_channel.input_lines ic) - |> List.iter print_endline - with Sys_error msg -> - Printf.eprintf "Failed to read from '%s': %s\n" filename msg; - exit 1 + (try In_channel.with_open_text filename (fun ic -> In_channel.input_lines ic) + with Sys_error msg -> + Printf.eprintf "Failed to read from '%s': %s\n" filename msg; + exit 1) + |> List.iter print_endline From 4e837fb948ee64512af2dfd63bd5498c62067f16 Mon Sep 17 00:00:00 2001 From: Auberon Lopez Date: Mon, 18 May 2026 11:34:01 -0700 Subject: [PATCH 3/3] Increased mundanity of sample text in OCaml FileIO --- archive/o/ocaml/file-input-output.ml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/archive/o/ocaml/file-input-output.ml b/archive/o/ocaml/file-input-output.ml index 4b57abd27..7efc8ae4c 100644 --- a/archive/o/ocaml/file-input-output.ml +++ b/archive/o/ocaml/file-input-output.ml @@ -1,20 +1,9 @@ let filename = "output.txt" -(* Some arbitrary interesting text for demo file reading and writing. - These are the 10 thunderwords from Joyce's Finnegans Wake. - See here for a great literary explanation if you're interested: - https://hatterscabinet.com/pages-fw/fwtheme-thunderwords.html *) let sample_text = - {|bababadalgharaghtakamminarronnkonnbronntonnerronntuonnthunntrovarrhounawnskawntoohoohoordenenthurnuk -Perkodhuskurunbarggruauyagokgorlayorgromgremmitghundhurthrumathunaradidillifaititillibumullunukkunun -klikkaklakkaklaskaklopatzklatschabattacreppycrottygraddaghsemmihsammihnouithappluddyappladdypkonpkot -Bladyughfoulmoecklenburgwhurawhorascortastrumpapornanennykocksapastippatappatupperstrippuckputtanach -Thingcrooklyexineverypasturesixdixlikencehimaroundhersthemaggerbykinkinkankanwithdownmindlookingated -Lukkedoerendunandurraskewdylooshoofermoyportertooryzooysphalnabortansporthaokansakroidverjkapakkapuk -Bothallchoractorschumminaroundgansumuminarumdrumstrumtruminahumptadumpwaultopoofoolooderamaunsturnup -Pappappapparrassannuaragheallachnatullaghmonganmacmacmacwhackfalltherdebblenonthedubblandaddydoodled -husstenhasstencaffincoffintussemtossemdamandamnacosaghcusaghhobixhatouxpeswchbechoscashlcarcarcaract -Ullhodturdenweirmudgaardgringnirurdrmolnirfenrirlukkilokkibaugimandodrrerinsurtkrinmgernrackinarockar + {|Some mundane sample text +Some sample text that is mundane +Another line of mundane sample text |} let () =