Request SML / NJ REPL for signatures or structures?

Is there a way to get a list signatureor structure, available in a top-level environment from the SML / NJ REPL? I am looking to get a list of signatures / structures that appear to be defined in files sources.cmin the sml source directory. Something along the lines

- signature s = LIST;

only listing bindings in a top-level environment.

+4
source share
1 answer

You can use 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 autoload EnvRef.listBoundSymbolsit will not return symbol names for available modules, but it is not loaded yet:

- boundSignatures ();
ENVREF
val it = () : unit
- signature S = STATICENV;
[autoloading]
[autoloading done]
- boundSignatures ();
STATICENV
ENVREF
S
val it = () : unit
+5
source

Source: https://habr.com/ru/post/1653962/


All Articles