printfn "%A" [1..1000]
inside f# 互动节目[1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22;
23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42;
43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62;
63; 64; 65; 66; 67; 68; 69; 70; 71; 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82;
83; 84; 85; 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; 100; ...]
以下设置不影响显示的列表成员数量fsi.PrintSize <- 222 // no effect
fsi.PrintLength <- 222 // no effect
fsi.PrintDepth <- 222 // no effect
fsi.PrintWidth <- 222 // no effect
fsi.ShowIEnumerable <- true // no effect
我问这个是因为我很打印记录,目前有些值被截断。所以最重要的问题是漂亮地打印没有截断值的记录 - 只是为了上下文。
%A 格式有很好的优势,因为它可以很好地布局记录,我不想通过使用 StructuredFormatDisplayAttribute 来松动。
这种格式化是使用 %A 格式化大对象的一部分,它可以完美运行,无需任何努力。所以我不是在问真正打印一个孤立的列表。
在 f# 源代码中:
在https://github.com/dotnet/fsharp/blob/b23b2a0f99f12ece94c5ad89aabb9169d51091f3/src/fsharp/utils/sformat.fs查看源代码
ObjectGraphFormatter 显然会进行格式化,接受格式选项。
最后几行可能是这样称呼它:
let internal anyToStringForPrintf options (bindingFlags:BindingFlags) (value, typValue) =
let formatter = ObjectGraphFormatter(options, bindingFlags)
formatter.Format (ShowAll, value, typValue) |> layout_to_string options
它由脚趾核心 Printf 模块调用,该模块又是内部的。
最佳答案
我想我会这样做:
[1..1000]
|> List.take 50
|> List.iter (printf "%A;")
关于f# - 在 F# 中使用 %A 格式时是否可以配置显示的列表项的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65765791/