Environment: Linux Mint 18.2, Ocaml 4.05.
I am writing a program which
Reads a file of lines of comma seperated data.
Breaks each line into seperate fields.
Applies checks (numeric, gender, first letter not a capital, etc…)
Reports any errors.
The code uses List.mapi to ‘iter’ over the data and return the results of checks on each field.
I am having troubles with test code which seemingly works in “utop” and fails to compile in ocamlc.
Utop code: # let process_field ctr word = (* Process/check each field of the record *) printf "%d %s\n" ctr (word "a"); process_field in "OK" ;; (* Test purposes.... *)
# let process_fields in_line = (* Check each field in 'in_line'. Report issues... *) begin (* String/Str function/s, requires 'str.cma' on ocamlc CLI *) let words = Str.split (Str.regexp "[,\t]+") in_line in List.mapi (process_field) words; (* Passes field index and data[index] *) end;; # process_fields "abc,def,ghi";;
Results displayed are;
# process_fields "abc,def,ghi";; 0 abc a 1 def a 2 ghi a - : string list = ["OK"; "OK"; "OK"]
The same code compiled with ocamlc results in the following error:
Error: Unbound value process_field… Line 37
Line 37 is the code in function "process_field" printf "%d %s\n" ctr (word "a"); process_field in
I am new to Ocaml and struggling with many things. Any help appreciated.