Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress "val it" output in Standard ML

Tags:

sml

smlnj

I'm writing a "script" in Standard ML (SML/NJ) that sets up the interactive environment to my liking. The last thing the script does is print out a message indicating everything went smoothly. Essentially, the last line is this:

print "SML is ready.\n";

When I run the script, all goes well but the SML interpreter displays the return value from the print function.

SML is ready.
val it = () : unit
-

Since I'm merely printing something to the screen, how can I suppress the "val it = () : unit" output so that all I see is the "SML is ready" message followed by the interpreter prompt?

like image 828
Barry Brown Avatar asked Aug 12 '09 09:08

Barry Brown


3 Answers

To surpress the SML-NJ prompt and response, use the following assignment.

Compiler.Control.Print.out := {say=fn _=>(), flush=fn()=>()};
print "I don't show my type";

I don't show my type

although I don't see why the print function returning the type is bad.

The say function controls what is printed out.

There is a larger example in the following SML/NJ notes http://www.cs.cornell.edu/riccardo/prog-smlnj/notes-011001.pdf

The useSilently function can be used to load a file but without displaying any output associated with the loading

fun useSilently (s) = let
val saved = !Compiler.Control.Print.out
fun done () = Compiler.Control.Print.out := saved
in
Compiler.Control.Print.out := {say = fn _ => (), flush = fn () => ()}
(use (s); done ()) handle _ => done ()
end

This is essentially changing the say function to do nothing and then setting it back at the end.

like image 104
pjp Avatar answered Nov 05 '22 23:11

pjp


Use this:

val _ = print "I don't show my type";
like image 35
Verbal Avatar answered Nov 06 '22 01:11

Verbal


In Moscow ML you can run the REPL without declaration output with

mosml -quietdec file.sml
like image 2
sshine Avatar answered Nov 06 '22 00:11

sshine