Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a6d417e36f6bb1154f4c003e6717e298 > files > 124

a-a-p-1.090-2mdv2009.0.noarch.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 36. Assignments</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="A-A-P Recipe Executive"><link rel="up" href="reference.html" title="Part III. Reference Manual"><link rel="prev" href="ref-variables.html" title="Chapter 35. Common Variables"><link rel="next" href="ref-attributes.html" title="Chapter 37. Attributes"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table width="100%" id="navtable"><tbody><tr><td align="left" class="left" width="33%"><b><a href="http://www.a-a-p.org">A-A-P home page</a></b></td><td align="center" class="center" width="34%"><b><a href="index.html">A-A-P Recipe Executive</a></b></td><td align="right" class="right" width="33%"></td></tr><tr><td align="left" class="left"><a accesskey="p" href="ref-variables.html">Prev</a></td><td align="center" class="center">Reference Manual</td><td align="right" class="right"><a accesskey="n" href="ref-attributes.html">Next</a></td></tr></tbody></table><hr><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ref-assign"></a>Chapter 36. Assignments</h2></div></div></div><h2><a name="id2682134"></a>Assignment</h2><p>
overview:
  </p><div class="informaltable"><table border="0"><colgroup><col width="150"><col></colgroup><tbody><tr><td>var = value</td><td>assign</td></tr><tr><td>var += value</td><td>append (assign if not set yet)</td></tr><tr><td>var ?= value</td><td>assign only when not set yet</td></tr><tr><td>var $= value</td><td>assign, evaluate when used</td></tr><tr><td>var $+= value</td><td>append, evaluate when used</td></tr><tr><td>var $?= value</td><td>assign only when not set, evaluate when used</td></tr></tbody></table></div><p>
</p><p>
Assignment with "+=" or "$+=" appends the argument as a separate item.  This
is actually done by inserting a space.  But when the variable wasn't set yet
and when it is empty it works like a normal assignment:
</p><pre class="programlisting">
        VAR += something
</pre><p>
is equal to:
</p><pre class="programlisting">
        @if globals().get("_no.VAR"):
        @   VAR = _no.VAR + " " + "something"
        @else:
        @   VAR = "something"
</pre><p>
Assignment with "?=" only does the assignment when the variable wasn't set
yet.  A variable that was set to an empty string also counts as being set.
Thus when using "aap VAR=" the empty value overrules the value set with "?=".
</p><pre class="programlisting">
        VAR ?= something
</pre><p>
is equal to:
</p><pre class="programlisting">
        @if not globals().has_key("_no.VAR"):
            VAR = something
</pre><p>
When using "$=", "$+=" or "$?=" variables in the argument are not evaluated at
the time of assignment, but this is done when the variable is used.  The
expansion is done in the scope where it is used, thus the result may depend on
when and where the variable is used..

</p><pre class="programlisting">
        VAR = 1
        TT $= $VAR
        VAR = 2
        :print $TT
</pre><p>

prints "2".
</p><p>
A variable with delayed evaluation cannot be used directly in Python code,
because it is set the the class ExpandVar.  See the 
<a href="ref-python.html#python-var2string">var2string()</a> function for
expanding the variable in Python code.
</p><p>
When first setting a variable with "$=" and later appending with "+=" the
evaluation is done before the new value is appended:

</p><pre class="programlisting">
        VAR = 1
        TT $= $VAR
        TT += 2
        VAR = 3
        :print $TT
</pre><p>

prints "1 2"
</p><p>
Note that evaluating a python expressions in `` is not postponed.
</p><h2><a name="id2682487"></a>Block Assignment</h2><p>
The normal assignment command uses a single line of text.  When broken into
several lines they are joined together, just like with other commands.  $BR can
be used to insert a line break.  Example:
</p><pre class="programlisting">
        foo = first line$BR
                second line$BR
                third line $BR
</pre><p>
The block assignment keeps the line breaks as they are.  The same example but
using a block assignment:
</p><pre class="programlisting">
        foo &lt;&lt; EOF
          first line
          second line
          third line 
            EOF
</pre><p>
The generic format is:
</p><pre class="programlisting">
        {var} &lt;&lt; {term}
        line1
        ...
        {term}
</pre><p>
{term} can be any string without white space.  The block ends when {term} is
found in a line by itself, optionally preceded by white space and followed by
white space and a comment.
</p><p>
The amount of indent to be removed from all the lines is set by the first
line.  When the first line should start with white space use $( ).
</p><p>
All the variations of the assignment command can be used:

  </p><div class="informaltable"><table border="0"><colgroup><col width="150"><col></colgroup><tbody><tr><td>var &lt;&lt; term</td><td>assign</td></tr><tr><td>var +&lt;&lt; term</td><td>append (assign if not set yet)</td></tr><tr><td>var ?&lt;&lt; term</td><td>only assign when not set yet</td></tr><tr><td>var $&lt;&lt; term</td><td>evaluate when used</td></tr><tr><td>var $+&lt;&lt; term</td><td>append, evaluate when used</td></tr><tr><td>var $?&lt;&lt; term</td><td>only when not set, evaluate when used</td></tr></tbody></table></div><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref-variables.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref-attributes.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 35. Common Variables </td><td width="20%" align="center"><a accesskey="h" href="index.html">
		    Contents</a></td><td width="40%" align="right" valign="top"> Chapter 37. Attributes</td></tr></table></div></body></html>