You are here:   ArielOrtiz.com > Programming Languages > Starting with Recursion

Starting with Recursion

Note: This is a class activity, nothing needs to be delivered.

Place all the requested functions and unit tests in a name space called arithmetic.

Assume you have these function definitions:

(defn add1 [x] (conj x ()))

(def sub1 rest)

(def equal-zero? empty?)

(def zero ()) 

Write in Clojure the functions described in the following table, using only add1, sub1, equal-zero?, zero, and any function written as part of this same exercise. Assume that the parameters a and b represent natural numbers (nonnegative integers).

Function Description
(add a b) Returns a plus b.
(subtract a b) Returns a minus b. Assume that ab.
(multiply a b) Returns a times b.
(equal? a b) Returns true if a is equal to b, otherwise returns false.
(less? a b) Returns true if a is less than b, otherwise returns false.
(quotient a b) Returns the quotient of dividing a by b.
(remainder a b) Returns the remainder of dividing a by b.
(power a b) Returns a raised to the power of b.
© 1996-2011 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid HTML5 | Valid CSS