如何自定义 SML/NJ 交互循环?

发布于 2024-07-16 07:57:05 字数 945 浏览 3 评论 0原文

我是标准 ML 的新手,我正在尝试了解 SML/NJ 运行时环境。 我想根据我的需要调整它。 具体来说,我想:

  • 默认使用 IntInf
  • 防止它截断字符串和 IntInf 到 70 个字符。

以下是我在 8 个多小时的阅读文档和实验中发现的内容。

我可以使用命令在 int 之上重载 IntInf

open IntInf;

我可以使用变量 Control.Print.stringDepth 控制显示字符串中的字符数。 例如,这将让它在截断之前显示 1000 个字符:

Control.Print.stringDepth := 1000;

How do I do the same for IntInf value? 我可以将深度设置为无限(即根本不截断)吗?

打开 IntInf 是用 IntInf 重载 int 的最佳方法吗?

最后,如何使这一切在运行时自动加载,以便当我调用“sml”时它位于我的默认环境中?


编辑:我发现有一个名为 Control.Print.intinfDepth 的选项可以设置为一个很大的数字(例如 999999)。 但我不知道如何使其无限。

我的其他问题仍然没有答案。


编辑:我在堪萨斯州遇到了这套 SML/NJ 自定义设置状态。 为了显示我自己的横幅消息并避免显示“val it = true : bool”,我需要测试 SMLofNJ.exportML 的返回值。 如果这是真的,则堆映像刚刚恢复(即启动),我可以显示一条消息。 如果为 false,则刚刚保存了堆映像。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2024-07-23 07:57:05

如何使这一切在运行时自动加载,以便当我调用“sml”时它位于我的默认环境中?

您需要创建一个由 sml 脚本运行的堆映像,然后您可以符号链接到该脚本。 为了避免引导的复杂性,我通常给我的堆映像一个不同的名称; 例如; sml-nw 适用于 SML/NJ,支持 noweb。

创建堆映像所需的基本原语是SMLofNJ.exportML。 使用方法如下:

  1. 按照您想要的方式设置所有内容,例如,打开 IntInf 并设置所有 Control.Print 变量。 (您可以尝试将 Control.Printthings 设置为valOf Int.maxInt`,这是最接近无穷大的值。)

  2. 通过 SMLofNJ.exportML "mysml" 创建一个新的堆映像。 当您启动自定义版本时,您将在调用 exportML 之后立即开始。 阅读文档。 玩耍; 有很多方法可以使用这个原语。

  3. 将堆映像(可能是mysml.x86-linux)复制到堆映像的安装目录(在我的安装中,/usr/lib/smlnj/bin/.heap) code>,但您可以按照 sml 脚本中的线索进行确认)

  4. 创建一个脚本 mysml,它是到 sml 脚本的符号链接。

在过去,这已经足够了,但我已经好几年没有使用 SML/NJ 了。 我还在网上发现了一个有些过时的示例

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文