输出在 REPL 中被 # 符号截断

发布于 2024-10-09 08:19:35 字数 520 浏览 0 评论 0原文

我编写了一个按预期工作的函数,但我不明白为什么输出是这样的。

功能:

datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;


(* XOR = (A And Not B) OR (Not A Or B) *)

local

fun do_xor (alpha,beta) = Or( And( alpha, Not(beta) ), Or(Not(alpha), beta))

in
fun xor (alpha,beta) = do_xor(alpha,beta);
end;

测试:

val result = xor(Atom "a",Atom "b");

输出:

val result = Or (And (Atom #,Not #),Or (Not #,Atom #)) : prop

I wrote a function which works as expected but i don't understand why the output is like that.

Function:

datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;


(* XOR = (A And Not B) OR (Not A Or B) *)

local

fun do_xor (alpha,beta) = Or( And( alpha, Not(beta) ), Or(Not(alpha), beta))

in
fun xor (alpha,beta) = do_xor(alpha,beta);
end;

Test:

val result = xor(Atom "a",Atom "b");

Output:

val result = Or (And (Atom #,Not #),Or (Not #,Atom #)) : prop

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

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

发布评论

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

评论(1

等你爱我 2024-10-16 08:19:35

这只是一个输出限制(是的,这很令人困惑) - 默认情况下,顶层(交互式 shell)中值打印输出的深度被限制为相当小的数字(即 5)。跳过的部分打印有#。

您可以使用 printDepth 变量覆盖此深度 - 至少在 SML-NJ 中:

Control.Print.printDepth := 1024;

PS 顺便说一句,您不需要单独的 do_xor 和本地函数 - 只

fun xor(alpha, beta) = Or(...);

需要即可。

This is just an output restriction (yes, it's confusing) - by default the depth of value printouts in the top-level (interactive shell) is limited to a fairly small number (i.e. 5). The skipped parts are printed with #.

You can override this depth - at least, in SML-NJ - with printDepth variable:

Control.Print.printDepth := 1024;

P.S. By the way, you don't need a separate do_xor and local function here - just

fun xor(alpha, beta) = Or(...);

will do.

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