ocamlocaml-toplevel

How are command line argument are treated in toplevel?


I have a program which takes command line argument. The same of source file is encode.ml. I want to load this file in the toplevel.

Is there way to load the source file in the toplevel where we can pass it a command line arguments?

Thanks.


Solution

  • Yes, invoke your toplevel with ocaml encode.ml arg1 arg2 etc. The following program demonstrates it:

    $ cat args.ml
    let () =
      Array.iteri (Printf.printf "%d -> %s\n") Sys.argv
    
    $ ocaml args.ml -h --help -help
    0 -> args.ml
    1 -> -h
    2 -> --help
    3 -> -help