Improve manual on inheriting attributes
Expands first paragraph a bit Adds a more comprehensive example
This commit is contained in:
		
							parent
							
								
									e09161d05c
								
							
						
					
					
						commit
						0167eac571
					
				
					 1 changed files with 30 additions and 2 deletions
				
			
		|  | @ -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, | ||||
|  | @ -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 | ||||
|  | @ -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> | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue