Discussion:
A nix pretty-printer and a trace function you can tell how deep it should go
(too old to reply)
Profpatsch
2017-06-12 15:33:40 UTC
Permalink
https://github.com/NixOS/nixpkgs/pull/26433

Pretty Printing:

nix-repl> lib.generators.toPretty {} { foo = [ 2 3 netcat-openbsd ]; bar = lib.id; x = {args, def ? 42}: args; }
"{ \"bar\" = <λ>; \"foo\" = [ 2 3 <δ> ]; \"x\" = <λ:{args,(def)}>; }"

nix-repl> lib.generators.toPretty {} (import <nixpkgs>)
"<λ:{(config),(crossSystem),(localSystem),(overlays),(platform),(system)}>"


Trace Folding:

nix-repl> foo = { a = [ 1 [ 2 3 ] ]; b = { c.d.e = "yip yip"; }; }

nix-repl> lib.traceValSeqN 10 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = { "e" = "yip yip"; }; }; }; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 3 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = {…}; }; }; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 1 foo
trace: { "a" = […]; "b" = {…}; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 0 foo
trace: {…}
{ a = [ ... ]; b = { ... }; }


https://twitter.com/Profpatsch/status/874127956884566016

I hope this helps some people.
Please review the code.
--
Proudly written in Mutt with Vim on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es
May take up to five days to read your message. If it’s urgent, call me.
Tomasz Czyż
2017-06-12 15:57:44 UTC
Permalink
nice, thank you
Post by Profpatsch
https://github.com/NixOS/nixpkgs/pull/26433
nix-repl> lib.generators.toPretty {} { foo = [ 2 3 netcat-openbsd ]; bar =
lib.id; x = {args, def ? 42}: args; }
"{ \"bar\" = <λ>; \"foo\" = [ 2 3 <Ύ> ]; \"x\" = <λ:{args,(def)}>; }"
nix-repl> lib.generators.toPretty {} (import <nixpkgs>)
"<λ:{(config),(crossSystem),(localSystem),(overlays),(
platform),(system)}>"
nix-repl> foo = { a = [ 1 [ 2 3 ] ]; b = { c.d.e = "yip yip"; }; }
nix-repl> lib.traceValSeqN 10 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = { "e" = "yip yip"; }; }; }; }
{ a = [ ... ]; b = { ... }; }
nix-repl> lib.traceValSeqN 3 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = {
}; }; }; }
{ a = [ ... ]; b = { ... }; }
nix-repl> lib.traceValSeqN 1 foo
trace: { "a" = [
]; "b" = {
}; }
{ a = [ ... ]; b = { ... }; }
nix-repl> lib.traceValSeqN 0 foo
trace: {
}
{ a = [ ... ]; b = { ... }; }
https://twitter.com/Profpatsch/status/874127956884566016
I hope this helps some people.
Please review the code.
--
Proudly written in Mutt with Vim on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es
May take up to five days to read your message. If it’s urgent, call me.
_______________________________________________
nix-dev mailing list
https://mailman.science.uu.nl/mailman/listinfo/nix-dev
--
Tomasz CzyŌ
Loading...