(sentence) => (((the cow) that ((the milk)) saw) drank bagels)It would be nice to get rid of all of the extra parentheses in the generated sentence. For example:
(sentence) => (the cow that the milk saw drank bagels)To do this, we need a function called flatten that takes an arbitrarily-nested list of symbols and returns a simple "flat" list containing all of the symbols, without any extra parentheses. Assuming we had such a function, we could rewrite sentence as follows:
(define sentence (lambda () (flatten (list (fancy-noun) (verb) (noun)))))Your job is to write the function flatten.
In other words, either the list is empty, or its car is a symbol, or its car is another arbitrarily-nested list. The built-in Scheme function symbol? can be used to test if something is a symbol. Don't hesitate to define other helping functions if you need them.