Ethiopian multiplication: Difference between revisions

m
(Added Scheme)
Line 1,555:
 
=={{header|Ursala}}==
{{incorrect|Ursala|The task specifies that examples should have separate functions for doubling, halving, and checking if a number is even.}}
The first implementation below relies on the representation of natural numbers as lists of bits,
lsb first, so that halving is the same as taking the tail, doubling
Line 1,573 ⟶ 1,572:
emul = sum:-0@rS+ odd@l*~+ ^|(~&,double)|\+ *-^|\~& @iNC ~&h~=0->tx :^/half@h ~&
</lang>
The program above makes use of the functions odd, double, and half, which respectively
 
check for whether a number is not even, double a given number, or perform truncating
division by two. These functions are imported from the nat library and would not be
be redefined in practice. To comply with the task specification, they can be defined
as follows.
<lang Ursala>
odd = ~&ihB
double = ~&iNiCB
half = ~&itB
</lang>
test program:
<lang Ursala>
Anonymous user