; Programmer name: Jaycelynn Goldberg ; Course: CS430 2:00 section ; Professor: Elizabeth Adams ; File name: printReverse.txt >(setq mylist (read)) (the quick brown fox jumped over the lazy dog) (THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG) ; the reverse function takes in two parameters ; the 'alist' parameter is the list to be printed in reverse order. ; the 'rev' parameter may be nil if you just want to print in reverse order ; otherwise the second parameter can be a list - which may or may not be nil ; and the method will append 'alist' in reverse order to the BEGINNING of the original 'rev' list, ; and then store this in the 'new' list > (defun reverse (alist rev) (cond ((not(eq(cadr alist) nil)) (setq new (cons (car alist) rev)) (reverse (cdr alist) new)) (t (setq new (cons (car alist) rev))))) REVERSE >(reverse mylist nil) (DOG LAZY THE OVER JUMPED FOX BROWN QUICK THE) > (setq list (read)) (The musical my fair lady was written by lerner and loewe and the musical Cinderella was written by Rodgers and Hammerstein) (THE MUSICAL MY FAIR LADY WAS WRITTEN BY LERNER AND LOEWE AND THE MUSICAL CINDER ELLA WAS WRITTEN BY RODGERS AND HAMMERSTEIN) > (reverse list nil) (HAMMERSTEIN AND RODGERS BY WRITTEN WAS CINDERELLA MUSICAL THE AND LOEWE AND LER NER BY WRITTEN WAS LADY FAIR MY MUSICAL THE) > (setq list (read)) (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28) (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28) > (reverse list nil) (28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1) ; uses pprint ; prints each atom on a separate line except what was originally the last atom and the second to last atom. >(defun reverse (alist rev) (cond ((not(eq(cadr alist) nil)) (setq new (cons (car alist) rev)) (reverse (cdr alist) new)) (t (setq new (cons (car alist) rev)) (pprint new))))