4

Is there a way to get a list of the signatures or structures available in the top-level environment from the SML/NJ REPL? I'm looking to get a listing of the signatures/structures that appear to be defined in the sources.cm files in the sml source directory. Something along the lines of

- signature s = LIST;

only listing the bindings in the top-level environment instead.

Rorschach
  • 31,301
  • 5
  • 78
  • 129

1 Answers1

5

You can make use of the internal structures that SML/NJ provides:

fun boundSignatures () =
  let
    fun isSignature symbol = Symbol.nameSpace symbol = Symbol.SIGspace
    val signatures = List.filter isSignature (EnvRef.listBoundSymbols ())
  in
    List.app (fn s => print (Symbol.name s ^ "\n")) signatures
  end

Please note that, due to autoloading, EnvRef.listBoundSymbols won't return symbol names for modules which are available, but haven't yet been loaded:

- boundSignatures ();
ENVREF
val it = () : unit
- signature S = STATICENV;
[autoloading]
[autoloading done]
- boundSignatures ();
STATICENV
ENVREF
S
val it = () : unit
Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
  • works great, thanks. To force the autoloading, I found I can call `CM.make("$/basis.cm")` to force the basis values to be added. – Rorschach Sep 08 '16 at 23:12
  • @jenesaisquoi thanks, I didn't know that. BTW, the parentheses are redundant in that call: `CM.make "$/basis.cm"`. In SML you only need parentheses when you need to explicitly specify associativity. they're not used as a syntax for function calls. A space is used to designate function calls. – Ionuț G. Stan Sep 09 '16 at 09:43