Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does nix maintain itself to be lazy? #46

Open
Animeshz opened this issue Oct 12, 2023 · 1 comment
Open

How does nix maintain itself to be lazy? #46

Animeshz opened this issue Oct 12, 2023 · 1 comment

Comments

@Animeshz
Copy link

Follow up from Nix Hour #19 at 7m51s

How does this work?

let
  x = y;
  y = { v = x; };
in
  x # or y

# { v = { v = «repeated»; }; }

Or a bit more complicated example,

let
  x = { v = x; w = y; };
  y = { p = x; q = y; };
in
  x

# { v = { v = «repeated»; w = { p = «repeated»; q = «repeated»; }; }; w = «repeated»; }

It does however, fails when its not referenced yet it refers to some undefined value:

let
  x = { v = y; };
in
  7

# error: undefined variable 'y'

Note: All ran in nix repl with/without :p in front.

Follow up questions after this,

  • How infinite recursion is detected by nix?
  • Evaluation order, does it matter, is there a catch in let ... in ...?
  • Any (interesting) high-level details about the evaluation order that makes nix do this.

This maybe goes a bit into nix internals, so I'm not sure if its a good fit for a Nix Hour talk, but its really interesting to see how lazy language evolve into this while still being written in a procedural language.

Thanks!

@Animeshz
Copy link
Author

Some related information (I recently found): https://nixos.wiki/wiki/Nix_Evaluation_Performance

YorikSar added a commit that referenced this issue Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant