Factors of an integer: Difference between revisions

m (→‎{{header|REXX}}: created more whitespace in output. -- ~~~~)
Line 1,299:
# If the incremental number divides evenly into the input number, both the incremental number and the quotient are added to the list of factors.
 
This implementation makes use of Mercury's "state variable notation" to keep a pair of variables for accumulation, thus allowing the implementation to be tail recursive. !Accumulator is syntax sugar for a *pair* of variables. One of them is an "in"-moded variable and the other is an "out"-moded variable. !:Accumulator is the "out" portion and !.Accumulator is the "in" portion in the ensuing code.
Note that this implementation is tail-recursive and uses tricks of unification to "magically" pull the "L" variable seemingly out of thin air.
 
Using the state variable notation avoids having to keep track of strings of variables unified in the code named things like Acc0, Acc1, Acc2, Acc3, etc.
 
===fac.m===