Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define member?
- (lambda (a lat)
- (cond
- ((null? lat) #f)
- (else(or (eq? (car lat) a)
- (member? a (cdr lat)))))))
- (define glue
- (lambda (beg res)
- (cond
- ((null? beg) res)
- (else
- (glue (cdr beg) (cons (car beg) res))))))
- (define reverseAndSort
- (lambda (beg res newRes)
- (cond
- ((null? res) newRes)
- (else
- (reverseList(reverseAndSort (cdr beg) (cdr res) (cons (glue (car beg) (reverseList (car res))) newRes)))))))
- (define (reverseList x)
- (if (null? x) '()
- (append (reverse (cdr x)) (list (car x)))))
- (define getResume
- (lambda (msg cur beg res)
- (cond
- ((null? msg) (reverseAndSort (reverseList beg) (cons cur res) '()))
- (else
- (cond
- ((eq? (car msg) 'resume) (getResume (cdr msg) '() beg (cons cur res)))
- ((getResume (cdr msg) (cons (car msg) cur) beg res)))))))
- (define getBegin
- (lambda (msg cur beg)
- (cond
- ((null? msg) #f)
- ((eq? (car msg) 'resume) (getResume (cdr msg) '() (cons cur beg) '())) ;Done w/ begins, find resumes
- (else
- (cond
- ((eq? (car msg) 'begin) (getBegin (cdr msg) '() (cons cur beg))) ;Start new begin list
- ((getBegin (cdr msg) (cons (car msg) cur) beg)) ))))) ;Put item in begin list
- (define parse
- (lambda (msg)
- (cond
- ((null? msg)'())
- ((eq? (car msg) 'begin) (getBegin(cdr msg) '() '()))
- (else(parse(cdr msg))))))
- (parse '(Bellingham Washington : Bejing China begin now is the time begin a stitch in
- time begin do not tie resume your shoe in a watermelon patch resume saves nine
- resume for all good men to come to the aid of their part))
Advertisement
Add Comment
Please, Sign In to add comment