From 1c9c0a5a46822be60c999f0196567c9e17cf5fa3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 2 Feb 2004 21:39:33 +0000 Subject: * Added syntactic sugar to the construction of attribute sets to `inherit' variables from the surrounding lexical scope. E.g., {stdenv, libfoo}: derivation { builder = ./bla; inherit stdenv libfoo; xyzzy = 1; } is equivalent to {stdenv, libfoo}: derivation { builder = ./bla; stdenv = stdenv; libfoo = libfoo; xyzzy = 1; } Note that for mutually recursive attribute set definitions (`rec {...}'), this also works, that is, `rec {inherit x;}' is equivalent to `let {fresh = x; body = rec {x = fresh;};}', *not* `rec {x = x}'. --- src/libexpr/nixexpr.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 7de3e823c4f4..b0f506e65d6f 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -181,16 +181,18 @@ Expr substitute(const ATermMap & subs, Expr e) } /* Idem for a mutually recursive attribute set. */ - ATermList bindings; - if (atMatch(m, e) >> "Rec" >> bindings) { + ATermList rbnds, nrbnds; + if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds) { ATermMap subs2(subs); - for (ATermIterator i(bindings); i; ++i) { + for (ATermIterator i(rbnds); i; ++i) { Expr e; if (!(atMatch(m, *i) >> "Bind" >> s >> e)) abort(); /* can't happen */ subs2.remove(s); } - return ATmake("Rec()", substitute(subs2, (ATerm) bindings)); + return ATmake("Rec(, )", + substitute(subs2, (ATerm) rbnds), + substitute(subs, (ATerm) nrbnds)); } if (ATgetType(e) == AT_APPL) { -- cgit 1.4.1