This assignment asks you to write a few recursive functions in Racket. The primary goal of this assignment is to gain more experience with common recursion patterns. For this assignment:
Download the files and use them as templates for your submission. Please use the names given for your files.
These file include a provide clause and a require clause, respectively. The former exports your five public functions for use by other files, and the latter imports your functions, enabling you to test them with Rackunit.
> (list-of? number? '(1 2 3 "Eugene" 4 5)) #f
<n-list> ::= () | (<number-exp> . <n-list>) <number-exp> ::= <number> | <n-list>nlist-abs returns an n-list identical in all respects to nlist except that each value have been replaced by its absolute value. For example:
> (nlist-abs '((((((1 -2 (3 -4)) 5 -6 ((7 (-8) 9 -10))) 11 -12)) 13 -14))) '((((((1 2 (3 4)) 5 6 ((7 (8) 9 10))) 11 12)) 13 14)) > (nlist-abs '(1 1 (-1) (-7 (21 0 21) 3) -4 (5 1))) '(1 1 (1) (7 (21 0 21) 3) 4 (5 1))nlist-abs should be mutually recursive with the function numberexp-abs, which returns the absolute value of a number expression. Recall that Racket includes an abs function.
<string-list> ::= () | (<string-exp> . <string-list>) <string-exp> ::= <string> | <string-list>max-length returns the length of the longest string in str-list. If str-list is the empty list, it returns -1. For example:
> (max-length '("Write" "a" "mutually" "recursive" "function" ("max-length" "str-list") "that" "takes" "one" "argument" ("a" "string-list"))) 11max-length should be mutually recursive with the function max-length-se, which processes a a string expression.
<prefix-exp> ::= (<operator> <number-exp> <number-exp>) <number-exp> ::= <number> | <prefix-exp> <operator> ::= <symbol>prefix->infix returns an equivalent infix expression as its value.
<infix-exp> ::= (<number-exp> <operator> <number-exp>) <number-exp> ::= <number> | <infix-exp> <operator> ::= <symbol>For example:
> (prefix->infix '(+ 4 5)) '(4 + 5) > (prefix->infix '(* (+ 4 5) (+ 7 6))) '((4 + 5) * (7 + 6))prefix->infix should be mutually recursive with the function number-expr>infix, which returns an infix version of a number expression. (This is a great place to use program derivation, if you like.)
> (reduce + 0 '(1 2 3 4)) ; ((((0 + 1) + 2) + 3) + 4) 10 > (reduce - 100 '(1 2 3 4)) ; ((((100 - 1) - 2) - 3) - 4) 90 > (reduce (lambda (result n) (* result (add1 n))) 1 '(1 2 5)) 36
By the due time and date, submit the following files:
Be sure that your submission follows the submission requirements.