Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Scheme (language) Develop a function named flatten, which takes an arbitrarily c

ID: 3776701 • Letter: S

Question

Scheme (language)

Develop a function named flatten, which takes an arbitrarily complicated list of primitives and sublists and generates a list with all the same primitives, in the same order, but without all the intervening parentheses. For example, (flatten ’(1 (2) 3)) returns (1 2 3); (flatten ’((1) (2 3 4) (5 6))) returns (1 2 3 4 5 6); (flatten ’(a (b (c d (e) f (g h))) (i j))) returns (a b c d e f g h i j); and (flatten ’(“nothing” “to” “flatten”)) returns (nothing to flatten)

There is no more info, that is the entire question

Explanation / Answer

(define flatten (lst) //I

(cond ((null lst) nil)

((atom lst) (list lst))

(t (append (flatten (car lst))

(flatten (cdr lst))))))

(f (cons (car lst) (flatten (cdr lst))))))