| libxexpr Reference Manual |
|---|
The empty arithmetic operators (<add/>, <subtract/>, <multiply/> and <divide/>) all evaluate to <nil/>.
The <add> and <subtract> operators change their first argument in some circumstances as in this example from the specification:
<while>
<gt><x/> 0</gt>
<expr>
<print newline="true"><x/><print>
<subtract><x/> 1</subtract>
</expr>
</while>
In general, the first agument will be modified if it is a function invocation that has no bindings and no arguments. Thus the following will print 9:
<define name="x"><multiply>2 3</multiply></define> <add><x/>3</add> <print><x/></print>
whereas this will print 6:
<define name="x"><multiply>2 3</multiply></define> <add><x unused=""/>3</add> <print><x/></print>
Where arguments are modified, this occurs as the arguments are being evaluated. Thus this expression:
<add><x/><x/><x/></add>
will multiply <x> by 4 rather than by 3.
The examples in the specification imply that <add> and <subtract> modify their first argument when it is a variable. The iterative example in section 8 wouldn't work if <multiply> worked the same way (and the definition of <2pi> in section 7 would not be expected to modify the definition of <pi> each time it is called). Note that this example is erroneous: IDs can't contain numbers.
It seems undesirable to modify functions that take arguments. Making the decision based on the invocation rather than the function definition makes expressions much easier to read.