File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed
doc/manual/source/language Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -443,7 +443,7 @@ three kinds of patterns:
443443 This works on any set that contains at least the three named
444444 attributes.
445445
446- It is possible to provide *default values* for attributes, in
446+ - It is possible to provide *default values* for attributes, in
447447 which case they are allowed to be missing. A default value is
448448 specified by writing `name ? e`, where *e* is an arbitrary
449449 expression. For example,
@@ -503,6 +503,45 @@ three kinds of patterns:
503503 > [ 23 {} ]
504504 > ```
505505
506+ - All bindings introduced by the function are in scope in the entire function expression; not just in the body.
507+ It can therefore be used in default values.
508+
509+ > **Example**
510+ >
511+ > A parameter (`x`), is used in the default value for another parameter (`y`):
512+ >
513+ > ```nix
514+ > let
515+ > f = { x, y ? [x] }: { inherit y; };
516+ > in
517+ > f { x = 3; }
518+ > ```
519+ >
520+ > This evaluates to:
521+ >
522+ > ```nix
523+ > {
524+ > y = [ 3 ];
525+ > }
526+ > ```
527+
528+ > **Example**
529+ >
530+ > The binding of an `@` pattern, `args`, is used in the default value for a parameter, `x`:
531+ >
532+ > ```nix
533+ > let
534+ > f = args@{ x ? args.a, ... }: x;
535+ > in
536+ > f { a = 1; }
537+ > ```
538+ >
539+ > This evaluates to:
540+ >
541+ > ```nix
542+ > 1
543+ > ```
544+
506545Note that functions do not have names. If you want to give them a name,
507546you can bind them to an attribute, e.g.,
508547
You can’t perform that action at this time.
0 commit comments