list-palindrome-predicates


A few more solutions to the list-palindrome problem. The first solution uses a named let and the second a map with an exit continuation. Both solutions are fragile (assuming eq? will do) and expensive (doing twice as much work as they need to when successful).

 (define (list-palindrome? l) 
  
   ; Return true iff the given list is an element-by-element palindrome.  
  
   (let lp? ((l1 l) (l2 (reverse l))) 
  
     (cond 
        ((null? l1) 
           #t) 
  
        ((eq? (car l1) (car l2)) 
           (lp? (cdr l1) (cdr l2))) 
  
        (#t 
           #f)))) 
  
  
 (define (list-palindrome? l) 
  
   ; Return true iff the given list is an element-by-element palindrome.  
  
   (call-with-current-continuation 
      (lambda (k) 
        (map (lambda (a b) (if (not (eq? a b)) (k #f))) l (reverse l)) 
        #t))) 

category-code