프로그래밍/OCaml
명령행 인자 처리 예제 for OCaml
Scripter
2013. 1. 26. 18:18
소스 파일명: testArguments.ml
- (*
- Filename: testArguments.ml
- Execute: ocaml testArguments.ml 1.2 2.1 3.00
- Or
- Compile: ocamlc -o testArguments testArguments.ml
- Execute: ./pyramidOfDigits2 1.2 2.1 3.00
- Or
- Compile: ocamlc -o testArguments.exe testArguments.ml
- Execute: testArguments 1.2 2.1 3.00
- Date: 2013. 1. 26.
- Copyright (c) pkim _AT_ scripts.pe.kr
- *)
- let main() =
- let args = Sys.argv in
- let args1 = Array.to_list args in
- let arr1 = List.tl args1 in
- let arr = List.map float_of_string arr1 in
- Printf.printf "Count of arguments: %d\n" (List.length arr);
- Printf.printf "The sum of arguments is %g\n" (List.fold_right (+.) arr 0.0);
- print_newline();;
- main();;
컴파일> ocamlc -o testArguments.exe testArguments.nl
실행> testArguments 5.2 7.9 -1.21
Count of arguments: 3
The sum of arguments is 11.89