I am having trouble writing a Scheme procedure that takes a list and returns the list created by switching successive elements in the list.
For example, if I were to call: (newlist ‘((a b) (c d) e f g))
I would get: ‘( (b a) (d c) f e g)
I have tried the following so far, but I am getting an error when trying to compile:
(define (newlist givenList)
(cond ; Condition statement
((null? givenList)
'())
((null? (cdr givenList))
(list (car givenList)))
(list (cadr givenList) (car givenList)))
(newlist (cddr givenList)))
cddr: contract violation expected: (cons/c any/c pair?) given: (g)
This language is very different from the ones I've previously worked with, so I'm admittedly a little stumped.