I would like to create a Scheme function that returns true if it is given a list consisting entirely of identical elements. Such a list would be "(1 1 1 1). That would give a lie with something like" (1 2 1 1).
This is what I have so far:
(define (list-equal? lst) (define tmp (car lst)) (for-each (lambda (x) (equal? x tmp)) lst) )
This is clearly not true, and I am new to this. I think I can not express the step at which I should return #t
or #f
.
Thanks in advance!
EDIT: I stumbled a bit and found a solution that works very well, and with a minimal amount of code:
(define (list-equal? lst) (andmap (lambda (x) (equal? x (car lst))) lst))
Thanks again for helping everyone.
source share