// file: fromBinaryLSBF.rex // author: Robert Keller // purpose: to create a number from a list of bits, most-significant bit first fromBinaryLSBF([]) => 0; fromBinaryLSBF([A | L]) => A + 2*fromBinaryLSBF(L); // Rationale: The empty list is converted to 0 for completeness // (there is no point having the function be undefined for []). // If A is the LSB of the number being created, that number is just // A + two times the number resulting from the rest of the bits. // For reference, below is an alternate version using an accumulator: /* fromBinaryLSBF(L) = fromBinaryLSBFaux(L, 1, 0); fromBinaryLSBFaux([], Power, Acc) => Acc; fromBinaryLSBFaux([A | L], Power, Acc) => fromBinaryLSBFaux(L, 2*Power, A*Power + Acc); */ sys(in, "toBinaryLSBF.rex"); // for test purposes test() = map(fromBinaryLSBF, map(toBinaryLSBF, range(0, 16)));