Lex
Lex

Reputation: 2096

polyml CommandLine.arguments() returns nonsense

I want to read some command line arguments from a compiled polyml program.

However, if I have a program like this:

print_args.ml

val args = CommandLine.arguments()

fun main () = app (fn s => (print s ; print "\n\n")) args

(which should just print its arguments and exit)

and I compile it with:

polyc print_args.ml -o print_args

and then run it like so:

./print_args foo bar

instead of seeing foo and bar in the output, I see the following:

-q

--error-exit

print_args.ml

/var/folders/kp/kh1w53hx6wbcbbbp5t1mr0hw0000gn/T//polyobj.5349.o

I suspect it is evaluating ComandLine.arguments() during compile time rather than at run time, and those arguments are some internal compiler things? But I don't know how to fix that. If that is the case, then CommandLine.arguments() appears to be rather useless. How do I get the runtime arguments in a polyml program? (Note, I have seen solutions for programs that are not compiled with polyc, but specifically want a compiled program)

Upvotes: 0

Views: 45

Answers (1)

Lex
Lex

Reputation: 2096

defining the args val inside of main forces the evaluation to be defered until run time

fun main () = let 
        val args = CommandLine.arguments()
    in  
        app (fn s => (print s ; print "\n\n")) args
    end 

Upvotes: 0

Related Questions