gpt4 book ai didi

sml - 在 sml 中扩展 #

转载 作者:行者123 更新时间:2023-12-04 10:21:16 26 4
gpt4 key购买 nike

假设我在 sml 中有一个非常大的列表,然后 sml 显示一些条目,然后开始显示 # 字符。

有人能告诉我如何查看整个列表吗?

最佳答案

假设这是 SML/NJ,您可以使用 printLength , printDepth和来自Control.Print的 friend 们结构体。

以下是来自 Control.Print 文档的片段。结构体:

printDepth
The depth of nesting of recursive data structure at which ellipsis begins.

printLength
The length of lists at which ellipsis begins.

stringDepth
The length of strings at which ellipsis begins.

因此,例如,我们可以通过更改 printLength 来更改我们不想在 REPL 中显示的列表元素的数量。引用
- Control.Print.printLength;
val it = ref 12 : int ref
- [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
val it = [1,2,3,4,5,6,7,8,9,10,11,12,...] : int list

- Control.Print.printLength := 18;
val it = () : unit
- [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
val it = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,...] : int list

- Control.Print.printLength := 100;
val it = () : unit
- [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
val it = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19] : int list

请注意,对于字符串和数据结构,省略号改为散列“#”。例如,这可以通过以下字符串看到。注意 val it = ... 末尾的“#”行,这是因为字符串的默认打印深度是 70 个字符:
- "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
val it = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusm#" : string

- Control.Print.stringDepth;
val it = ref 70 : int ref

最后,这是一个如何在嵌套数据结构中看到的示例:
- Control.Print.printDepth;
val it = ref 5 : int ref
- SOME (SOME (SOME (SOME (SOME (SOME (SOME 42))))));
val it = SOME (SOME (SOME (SOME (SOME #))))
: int option option option option option option option

- Control.Print.printDepth := 10;
val it = () : unit
- SOME (SOME (SOME (SOME (SOME (SOME (SOME 42))))));
val it = SOME (SOME (SOME (SOME (SOME (SOME (SOME 42))))))
: int option option option option option option option

无论多长,这两个建议的解决方案都会打印整个列表。

关于sml - 在 sml 中扩展 #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5051081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com