Suppress “val it” output in Standard ML

后端 未结 3 982
小蘑菇
小蘑菇 2021-01-11 19:16

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 eve

相关标签:
3条回答
  • 2021-01-11 19:28

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

    mosml -quietdec file.sml
    
    0 讨论(0)
  • 2021-01-11 19:39

    Use this:

    val _ = print "I don't show my type";
    
    0 讨论(0)
  • 2021-01-11 19:41

    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.

    0 讨论(0)
提交回复
热议问题