Skip to content

Commit

Permalink
elements in lists are lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
urbas committed Jul 12, 2023
1 parent 0b1d3e7 commit 08d68d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ implemented.

- πŸŒ• stage 0: evaluate basic expressions, rec attrsets, let bindings, `with`
statement, functions
- πŸŒ– stage 1:
- πŸŒ– lazy evaluation (missing: lazy evaluation in lists)
- πŸŒ• stage 1: lazy evaluation
- 🌘 stage 2:
- 🌘 built-in functions (progress: 1 out of 111)
- πŸŒ‘ derivations (hello world derivation)
Expand Down
8 changes: 7 additions & 1 deletion src/eval/nix_v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ fn emit_let_in(let_in: &ast::LetIn, out_src: &mut String) -> Result<(), String>
fn emit_list(list: &ast::List, out_src: &mut String) -> Result<(), String> {
*out_src += "new n.NixList([";
for element in list.items() {
out_src.push_str("new n.Lazy(ctx,(ctx) => ");
emit_expr(&element, out_src)?;
*out_src += ",";
out_src.push_str("),");
}
*out_src += "])";
Ok(())
Expand Down Expand Up @@ -1230,4 +1231,9 @@ mod tests {
fn test_eval_builtin_head() {
assert_eq!(eval_ok("builtins.head [ 1 2 ]"), Value::Int(1));
}

#[test]
fn test_eval_lists_are_lazy() {
assert_eq!(eval_ok("builtins.head [ 1 (1 / 0) ]"), Value::Int(1));
}
}

0 comments on commit 08d68d8

Please sign in to comment.