Palindrome using lists

Scheme

Public Domain

Given a sentence, this code finds the palindrome or the sentence

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(define (palindrome list)  ;List is passed to his function by user
  (reverse-lon list list)) ;List is then sent to another function that
                           ;handles actual palndrome work

(define (reverse-lon alist blist)
  (cond
   [(null? list) empty]
   [else
	(append alist (addright (car blist) (reverse (cdr blist))))]))
        ;Appends original list and reversed list
        ;calls addright on first element of list

(define (addright elem list) ;@params: first element of list, reverse cdr(list)
  (cond
   [ (null? list) (cons elem list) ]
   [ else 
	 (cons (car list) (addright elem (cdr list)))]))

(palindrome '(I love scheme))