tags:

views:

366

answers:

2

I'm new to Standard ML and I'm trying to get my head around the SML/NJ runtime environment. I want to adapt it to my needs. Specifically, I want to:

  • Use IntInf by default
  • Prevent it from truncating strings and IntInf to 70 characters.

Here's what I've found in my 8+ hours reading documentation and experimenting.

I can overload IntInf on top of int with the command

open IntInf;

I can control how many characters in a string are displayed with the variable Control.Print.stringDepth. For example, this will let it display 1000 characters before truncating:

Control.Print.stringDepth := 1000;

How do I do the same for IntInf values? Can I set the depth to be infinite (that is, no truncation at all)?

Is opening IntInf the best way to overload int with IntInf?

Finally, how to I make this all load automatically at runtime so that when I invoke "sml" it's in my default environment?


Edit: I've since found out there is an option called Control.Print.intinfDepth that can be set to a large number (say, 999999). I don't know how to make it infinite, though.

My other questions still remain unanswered.


Edit: I ran across this set of SML/NJ customizations for a class at Kansas State. To display my own banner message and avoid displaying "val it = true : bool" I need to test the return value of SMLofNJ.exportML. If it's true, the heap image was just restored (ie, started up) and I can display a message. If it's false, the heap image was just saved.

A: 

Does this help?

http://archives.devshed.com/forums/programming-132/big-integers-in-sml-nj-97t-316791.html

Not sure about infinite question.

gknauth
+2  A: 

How do I make this all load automatically at runtime so that when I invoke "sml" it's in my default environment?

You need to create a heap image to be run by the sml script, which you can then symbolically link to. To avoid complications of bootstrapping, I usually give my heap image a different name; for example; sml-nw for SML/NJ with support for noweb.

The basic primitive you need to create a heap image is SMLofNJ.exportML. Here's how you use it:

  1. Set up everything the way you want it by, e.g., open IntInf and setting all your Control.Print variables. (You could try setting Control.Print things to valOf Int.maxInt`, which is the closest thing to infinity.)

  2. Create a new heap image by SMLofNJ.exportML "mysml". When you start your customized version, you'll begin right after the call to exportML. Read the documentation. Play around; there are a lot of ways to use this primitive.

  3. Copy the heap image (maybe mysml.x86-linux) to the installation directory for heap images (on my installation, /usr/lib/smlnj/bin/.heap, but you can follow clues in the sml script to be sure)

  4. Create a script mysml that is a symbolic link to the sml script.

In the old days this was enough, but I haven't been using SML/NJ for several years now. I also found a somewhat outdated example on the web.

Norman Ramsey
Thanks. I did find that in the documentation and it works, but I figured there must be a better way that preserves the usual "welcome" banner message and doesn't display "val it = true : bool" upon startup. You use Moscow ML normally?
Barry Brown
See my second edit text in the original question.
Barry Brown
@Barry: if you want to avoid a 'val it = ...' message you'll have to figure out how to make a call to the top-level read/eval/print loop. Compiler.Interact.interact looks promising, but it's inexplicably missing from my installation.
Norman Ramsey
@Barry: These days my functional programming is lagely OCaml or Haskell. When I compile legacy SML code it is usually with MLton.
Norman Ramsey
@Barry: I've now reported a bug to SML/NJ and they've agree that the functionality advertised in Compiler.Interact.interact seems to have gone missing...
Norman Ramsey