Exercise 2.20 . The procedures + , * , and list take arbitrary numbers of argume
ID: 3617867 • Letter: E
Question
Exercise 2.20 . The procedures +, *, andlist take arbitrary numbers of arguments. One way todefine such procedures is to use define withdotted-tail notation. In a procedure definition, aparameter list that has a dot before the last parameter nameindicates that, when the procedure is called, the initialparameters (if any) will have as values the initial arguments, asusual, but the final parameter's value will be a list ofany remaining arguments. For instance, given thedefinition
(define (f x y . z) <body>)
the procedure f can be called with two or morearguments. If we evaluate
(f 1 2 3 4 5 6)
then in the body of f, x will be 1, ywill be 2, and z will be the list (3 4 5 6).Given the definition
(define (g . w) <body>)
the procedure g can be called with zero or morearguments. If we evaluate
(g 1 2 3 4 5 6)
then in the body of g, w will be the list(1 2 3 4 5 6).11
Use this notation to write a procedure same-parity thattakes one or more integers and returns a list of all the argumentsthat have the same even-odd parity as the first argument. Forexample,
(same-parity 1 2 3 4 5 6 7)
(1 3 5 7)
(same-parity 2 3 4 5 6 7)
(2 4 6)
Explanation / Answer
> (same-parity 2 3 4 5 6 7)
(2 4 6)
> (same-parity 1 2 3 4 5 6 7)
(1 3 5 7)
>
> (same-parity 2 3 4 5 6 7)
(2 4 6)
> (same-parity 1 2 3 4 5 6 7)
(1 3 5 7)
>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.