Skip to content

Commit

Permalink
Improve manual on inheriting attributes
Browse files Browse the repository at this point in the history
Expands first paragraph a bit
Adds a more comprehensive example
  • Loading branch information
typetetris committed Jan 27, 2018
1 parent e09161d commit 0167eac
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions doc/manual/expressions/language-constructs.xml
Expand Up @@ -61,7 +61,7 @@ evaluates to <literal>"foobar"</literal>.

<simplesect><title>Inheriting attributes</title>

<para>When defining a set it is often convenient to copy variables
<para>When defining a set or in a let-expression it is often convenient to copy variables
from the surrounding lexical scope (e.g., when you want to propagate
attributes). This can be shortened using the
<literal>inherit</literal> keyword. For instance,
Expand All @@ -72,7 +72,15 @@ let x = 123; in
y = 456;
}</programlisting>

evaluates to <literal>{ x = 123; y = 456; }</literal>. (Note that
is equivalent to

<programlisting>
let x = 123; in
{ x = x;
y = 456;
}</programlisting>

and both evaluate to <literal>{ x = 123; y = 456; }</literal>. (Note that
this works because <varname>x</varname> is added to the lexical scope
by the <literal>let</literal> construct.) It is also possible to
inherit attributes from another set. For instance, in this fragment
Expand Down Expand Up @@ -101,6 +109,26 @@ variables from the surrounding scope (<varname>fetchurl</varname>
<varname>libXaw</varname> (the X Athena Widgets) from the
<varname>xlibs</varname> (X11 client-side libraries) set.</para>

<para>
Summarizing the fragment

<programlisting>
...
inherit x y z;
inherit (src-set) a b c;
...</programlisting>

is equivalent to

<programlisting>
...
x = x; y = y; z = z;
a = src-set.a; b = src-set.b; c = src-set.c;
...</programlisting>

when used while defining local variables in a let-expression or
while defining a set.</para>

</simplesect>


Expand Down

0 comments on commit 0167eac

Please sign in to comment.