19 sep 2012 kl. 18.00 skrev David Matthews:
The problem is that there may be more than one ML command on a line and there has to be a consistent way to deal with it. In my view Poly/ML is consistent about this. The compiler reads exactly as many characters as it needs to form a valid ML "program" and leaves the input pointer pointing at the next character. When the "program" has completed executing the compiled code, which may consume further characters from the input, the read-eval-print loop returns to the compiler to start compiling ML. Consider the following input:
TextIO.inputLine TextIO.stdIn; 1; 2;
With Poly/ML this prints: val it = SOME " 1;\n": string option val it = 2: int
With SML/NJ it prints val it = SOME "2;\n" : string option val it = 1 : int
As far as I'm aware the Definition does not describe what should happen here.
No, I don't think so either, but even so would be good for different ML systems to have the same behaviour.
Also the same ML code *will* behave differently when run interactively or stand-alone using Poly/ML:
Poly/ML 5.5.0 Release
fun f() = (print "Say something: "; TextIO.inputLine TextIO.stdIn; print "Thank you.\n");
val f = fn: unit -> unit
PolyML.export("test",f);
val it = (): unit
f();Hello
Say something: Thank you. val it = (): unit
unix> ./test Say something: Hello Thank you.
I believe that the stand-alone behavior is the reasonable one -- it also agrees with SML/NJ and Moscow ML.
Does this cause problems? Yes, for me it does. We use ML in the introductory programming course for CS majors and it causes unnecessary complications for the students.
Lars-Henrik
Lars-Henrik Eriksson, PhD, Senior Lecturer Computing Science, Dept. of Information Technology, Uppsala University, Sweden E-mail: lhe@it.uu.se, Web: http://www.it.uu.se/katalog/lhe?lang=en Phone: +46 18 471 10 57, Mobile: +46 705-36 39 16, Fax: +46 18 51 19 25