소스 파일명: testArguments.ml

  1. (*
  2.    Filename: testArguments.ml
  3.    Execute: ocaml testArguments.ml 1.2 2.1 3.00
  4.      Or
  5.    Compile: ocamlc -o testArguments testArguments.ml
  6.    Execute: ./pyramidOfDigits2 1.2 2.1 3.00
  7.      Or
  8.    Compile: ocamlc -o testArguments.exe testArguments.ml
  9.    Execute: testArguments 1.2 2.1 3.00
  10.    Date: 2013. 1. 26.
  11.    Copyright (c) pkim _AT_ scripts.pe.kr
  12. *)
  13. let main() =
  14.     let args = Sys.argv in
  15.     let args1 = Array.to_list args in
  16.     let arr1 = List.tl args1 in
  17.     let arr = List.map float_of_string arr1 in
  18.     Printf.printf "Count of arguments: %d\n" (List.length arr);
  19.     Printf.printf "The sum of arguments is %g\n" (List.fold_right (+.) arr 0.0);
  20.     print_newline();;
  21. 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


 

Posted by Scripter
,