'how can i create function to check all elements in list are palindrome

i am trying to create a function which checks if all the elements in a list are palindrome.In my list i have two elements which are both palindrome,but my function will return false unless i only have one element which is palindrome,how can i make racket check everything in the list to see if they are all palindrome to each other and if there is one element in the list which is not palindrome it should return false.

(define list1 '("redivider" "madam" ))

(define palindromic?
  (lambda (li)
    (equal? li (reverse li))))

here is my outcome

( palindromic? list1)
#f


Solution 1:[1]

Be careful with reverse- that's function for lists, not for strings:

> (reverse '(1 2 3))
'(3 2 1)

> (reverse "madam")
. . reverse: contract violation
  expected: list?
  given: "madam"

You will need something like this:

(define (string-reverse s)
  (list->string (reverse (string->list s))))
 
> (string-reverse "aoeu")
"ueoa"

Use this function in palindromic?:

(define (palindromic? s)
  (equal? s (string-reverse s)))

> (palindromic? "madam")
#t
> (palindromic? "foo")
#f

Then use andmap:

> (andmap palindromic? '("madam" "redivider"))
#t
> (andmap palindromic? '("madam" "redivider" "foobar"))
#f

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Půda