More Help with Scheme, ML, and Prolog programs 

Forum: U Chicago, Com Sci 221 old messages, autumn 2000
Re: News Assignment #1, due 2 October (Mike O'Donnell)
Date: 2000, Sep 28
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

Here are the programs that we have been working on in class. They contain some deliberate errors that you need to find and fix if you use them in the assignment.


(define (reverseList listin)
  (cond ((null? listin) ())
        (#t (append (car listin) (reverseList (cdr listin))))))

(define (addtoend itemin listin)
  (cond ((null? listin) (list itemin)
        (#t (cons (car listin) (addtoend itemin (cdr listin)))))))

fun addtoend item []             = [item]
 |  addtoend item (head :: tail) = head :: (addtoend item tail)
 ;

fun reverseList []             = []
 |  reverseList (head :: tail) = addtoend head (reverseList tail)
 ;

addtoend(Item, [], [item]).

addtoend(Item, [Head | ShortTail], [Head | LongTail]) :-
	addtoend(Item, ShortTail, LongTail).

reverseList([], []).

reverseList([Head | Tail], ReversedList) :-
	reverseList(Tail, ReversedTail),
	addtoend(Head, ReversedList, ReversedTail).



Mike O'Donnell


Messages

to: "Help with Scheme, ML, and Prolog programs"