Quieting FSI output
At first I thought that such mode doesn’t make sense as FSI outputs gazillion of useful bits and pieces, but on further consideration found it may be of certain use sometimes.
So, the initial approach attempt was to somehow use –quiet setting upon starting FSI session. But unfortunately this is an “all or none” option, being set it suppresses FSI’s output to the stdout stream altogether. Thinking along this line I recalled that stderr stream continues to be active regardless of quieting stdout, hence using eprintf/eprintfn in place of printf/printfn must do the trick. And it does, indeed. This is where I stopped on Stack Overflow.
Further thinking was along the lines that having two different code versions for quiet and normal FSI modes is an inconvenience, if not too much burden. This is where F# shadowing in concert with –use: come into play. Using the following FSI script Quiet.fsx below that basically redirects stdout output into stderr will do the trick:
#if INTERACTIVE let printf fmt = Microsoft.FSharp.Core.Printf.eprintf fmt let printfn fmt = Microsoft.FSharp.Core.Printf.eprintfn fmt #endif
The only matter left is providing both FSI options on startup. I’ll show how to do this for FSI fired within Visual studio. Similarly, for autonomous FSI run these options should be placed on command line.
Thinking of placing Quiet.fsi script I finally chose my user directory, which has permanent relative location against FSI default startup directory; if you prefer another arrangement, then adjust accordingly:
Now, in normal mode the following script
let a = 1 printfn "The value of a is %d" a
produces quite verbose output:
Microsoft (R) F# Interactive version 11.0.60610.1
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
The value of a is 1
val a : int = 1
val it : unit = ()
In quiet mode the same script’s output will be as terse as:
The value of a is 1