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.
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:
Set up everything the way you want it by, e.g.,
open IntInf
and setting all yourControl.Print
variables. (You could try setting Control.Printthings to
valOf Int.maxInt`, which is the closest thing to infinity.)Create a new heap image by
SMLofNJ.exportML "mysml"
. When you start your customized version, you'll begin right after the call toexportML
. Read the documentation. Play around; there are a lot of ways to use this primitive.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 thesml
script to be sure)Create a script
mysml
that is a symbolic link to thesml
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.
Does this help?
http://archives.devshed.com/forums/programming-132/big-integers-in-sml-nj-97t-316791.html
Not sure about infinite question.
来源:https://stackoverflow.com/questions/740896/how-can-i-customize-the-sml-nj-interactive-loop