mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
* 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}'.
This commit is contained in:
parent
d9f30fe7c7
commit
1c9c0a5a46
6 changed files with 78 additions and 41 deletions
|
@ -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(<term>)", substitute(subs2, (ATerm) bindings));
|
||||
return ATmake("Rec(<term>, <term>)",
|
||||
substitute(subs2, (ATerm) rbnds),
|
||||
substitute(subs, (ATerm) nrbnds));
|
||||
}
|
||||
|
||||
if (ATgetType(e) == AT_APPL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue