[17]matica:~$ poly Poly/ML 5.4.1 Release
fun main () = raise Domain ;
val main = fn: unit -> 'a
PolyML.export ("foo", main);
val it = (): unit
[19]matica:~$ cc -o foo foo.o -lpolymain -lpolyml [20]matica:~$ ./foo [21]matica:~$ echo $? 0
I find this quite surprising, am I the only one?
I know that I can easily work around it by including an exception catching wrapper in main, but it seems to me that wrapper should be in libpolymain ..
On 05/01/12 20:03, Ian Zimmerman wrote:
[17]matica:~$ poly Poly/ML 5.4.1 Release
fun main () = raise Domain ;
val main = fn: unit -> 'a
PolyML.export ("foo", main);
val it = (): unit
[19]matica:~$ cc -o foo foo.o -lpolymain -lpolyml [20]matica:~$ ./foo [21]matica:~$ echo $? 0
I find this quite surprising, am I the only one?
I know that I can easily work around it by including an exception catching wrapper in main, but it seems to me that wrapper should be in libpolymain ..
There is also the a similar question about what happens when processing SML scripts on stdIn, e.g. for
echo "fun f () : unit = raise Domain; f ();" | poly
we still get a successful exit value.
On many occasions when writing make files I would have found it useful to have an exception raised above, to stop processing on an error. I have always simply wrapped with something that prints out the exception and explicitly sets an exit status via OS.Process.exit. (For my make files, the f is PolyML.use.)
Phil
I agree that this surprising. It's surprised me a number of times, usually not in an agreeable way. I don't so much mind the absence of message, but the 0 exit code is painful.
Michael
On 06/01/2012, at 7:03, Ian Zimmerman itz@buug.org wrote:
[17]matica:~$ poly Poly/ML 5.4.1 Release
fun main () = raise Domain ;
val main = fn: unit -> 'a
PolyML.export ("foo", main);
val it = (): unit
[19]matica:~$ cc -o foo foo.o -lpolymain -lpolyml [20]matica:~$ ./foo [21]matica:~$ echo $? 0
I find this quite surprising, am I the only one?
I know that I can easily work around it by including an exception catching wrapper in main, but it seems to me that wrapper should be in libpolymain ..
-- Ian Zimmerman gpg public key: 1024D/C6FF61AD fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD Rule 420: All persons more than eight miles high to leave the court. _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On Thu, 5 Jan 2012, Ian Zimmerman wrote:
[17]matica:~$ poly Poly/ML 5.4.1 Release
fun main () = raise Domain ;
val main = fn: unit -> 'a
PolyML.export ("foo", main);
val it = (): unit
[19]matica:~$ cc -o foo foo.o -lpolymain -lpolyml [20]matica:~$ ./foo [21]matica:~$ echo $? 0
I find this quite surprising, am I the only one?
I know that I can easily work around it by including an exception catching wrapper in main, but it seems to me that wrapper should be in libpolymain ..
I am not surprised, maybe because I am used to it for many years, and have my own wrappers to do the right thing.
What is "right" depends on the situation. In particular there are at least two main classes of ML exceptions: regular or Interrupt, potentially further derived things like TimeOut. If Poly/ML would take a certain default action wrt. process exit, one would have to modify this in the application anyway. Also note that the same question arises again for ML threads: a final exception is absorbed, but can be easily treated by a user-space wrapper. (The main function above is probably associated with a certain default ML thread, but David should be able to explain this better.)
Makarius
On 06/01/2012 09:46, Makarius wrote:
On Thu, 5 Jan 2012, Ian Zimmerman wrote:
[17]matica:~$ poly Poly/ML 5.4.1 Release
fun main () = raise Domain ;
val main = fn: unit -> 'a
PolyML.export ("foo", main);
val it = (): unit
[19]matica:~$ cc -o foo foo.o -lpolymain -lpolyml [20]matica:~$ ./foo [21]matica:~$ echo $? 0
I find this quite surprising, am I the only one?
I know that I can easily work around it by including an exception catching wrapper in main, but it seems to me that wrapper should be in libpolymain ..
The current code forks off the root function and terminates when the last thread exits. It does not treat the first thread as special and it is possible for that thread to fork other threads and for it to exit while leaving the Poly process running. Since a thread can exit either by returning or by raising an uncaught exception it isn't clear when a non-zero return code should be generated.
That seemed to me to be a reasonable approach but I'm prepared to consider other possibilities. The alternative would be to wrap the main function as (f (); OS.Process.exit OS.Process.success) handle _ => OS.Process.exit OS.Process.failure I suppose it would be possible for the initial thread to exit with Thread.exit to avoid calling OS.Process.exit if it wanted to leave other threads running.
David