3

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.

Barry Brown
  • 20,233
  • 15
  • 69
  • 105

2 Answers2

3

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.Printthings tovalOf 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
  • 198,648
  • 61
  • 360
  • 533
  • 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 May 02 '09 at 18:15
  • @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 May 02 '09 at 21:51
  • @Barry: These days my functional programming is lagely OCaml or Haskell. When I compile legacy SML code it is usually with MLton. – Norman Ramsey May 02 '09 at 21:52
  • 1
    @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 May 03 '09 at 01:40
0

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,310
  • 2
  • 29
  • 44