I am trying to write a function that returns T/F in regards to if a a list contains elements that are list(s) with exactly two elements which can be any expressions. I am pretty new to Scheme and have been stuck on how to determine how to go about doing this. I have tried everything from using if, cond, and lambda with no success. It seems I am having trouble figuring out how to have Scheme traverse through the entire list and returning whether it is T/F at the end.
Some examples of what I am looking for:
(foobar? '((a 1)(b 2)))
#t
(foobar? '((foo 100)(bar 2 3)))
#f
(foobar? '((a 1) b (c 3)))
#f
(foobar? '((a 1) . 2))
#f
Any help would be much appreciated.
has-two-elements?that determines whether a single list has exactly two elements. That shouldn’t be too hard.Write a recursive function
all-have-two-elements?that determines whether all elements of a list are lists of exactly two elements. There are two cases to consider:#t.(has-two-elements? (car l))and(all-have-two-elements? (cdr l))must both be true.That’s seven lines of code if you indent properly.