I'm currently studying Scheme and encounter a question which description such like: Define and implement a function that takes something like a logical operator check
and a list xs
, then check whether that (check a b)
evaluate to true for all two near by element a
b
in list xs
.
Some example below like:
(check < '(15 16 17 18))
#t
(check > '(5))
#t
(check > '())
#t
(check (lambda (a b) (eq? b (+ a 1))) '(11 12 13))
#t
(check eq? '(4 4 5))
#f
In my view, I think this question similar to check a list is sorted in increasing order or not, but the implementation may have some difference.
I intend to define a recursive function involved with foldl
and do some conditional checks, but my question is how to detect which the logical operator is and how they doing their work in my code, so anyone could help with it? Thank you in advance.