Skip to content

Instantly share code, notes, and snippets.

@mjambon
Created September 27, 2011 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjambon/1246539 to your computer and use it in GitHub Desktop.
Save mjambon/1246539 to your computer and use it in GitHub Desktop.
Embed the contents of a file into an OCaml program.
let quote ic =
let buf = Buffer.create 1000 in
Buffer.add_string buf "\
let contents =
\"";
try
while true do
Buffer.add_string buf (String.escaped (input_line ic));
Buffer.add_char buf '\n';
done;
assert false
with End_of_file ->
Buffer.add_char buf '"';
print_endline (Buffer.contents buf)
let () = quote stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment