Guest User

Untitled

a guest
May 2nd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.72 KB | None | 0 0
  1. (define member?
  2.   (lambda (a lat)
  3.     (cond
  4.       ((null? lat) #f)
  5.       (else(or (eq? (car lat) a)
  6.                (member? a (cdr lat)))))))
  7.  
  8. (define glue
  9.   (lambda (beg res)
  10.     (cond
  11.       ((null? beg) res)
  12.       (else
  13.        (glue (cdr beg) (cons (car beg) res))))))
  14.  
  15. (define reverseAndSort
  16.   (lambda (beg res newRes)
  17.     (cond
  18.       ((null? res) newRes)
  19.       (else
  20.       (reverseList(reverseAndSort (cdr beg) (cdr res) (cons (glue (car beg) (reverseList (car res))) newRes)))))))
  21.  
  22. (define (reverseList x)
  23.          (if (null? x) '()
  24.               (append (reverse (cdr x)) (list (car x)))))
  25.  
  26. (define getResume
  27.   (lambda (msg cur beg res)
  28.     (cond
  29.       ((null? msg) (reverseAndSort (reverseList beg) (cons cur res) '()))
  30.       (else
  31.        (cond
  32.          ((eq? (car msg) 'resume) (getResume (cdr msg) '() beg (cons cur res)))
  33.          ((getResume (cdr msg) (cons (car msg) cur) beg res)))))))
  34.  
  35. (define getBegin
  36.   (lambda (msg cur beg)
  37.     (cond
  38.       ((null? msg) #f)
  39.       ((eq? (car msg) 'resume) (getResume (cdr msg) '() (cons cur beg) '()))    ;Done w/ begins, find resumes
  40.       (else
  41.        (cond
  42.          ((eq? (car msg) 'begin) (getBegin (cdr msg) '() (cons cur beg))) ;Start new begin list
  43.          ((getBegin (cdr msg) (cons (car msg) cur) beg)) )))))            ;Put item in begin list
  44.  
  45.  
  46. (define parse
  47.   (lambda (msg)
  48.     (cond
  49.       ((null? msg)'())
  50.       ((eq? (car msg) 'begin) (getBegin(cdr msg) '() '()))
  51.       (else(parse(cdr msg))))))
  52.  
  53.  
  54.  
  55.          
  56.      
  57. (parse '(Bellingham Washington : Bejing China begin now is the time begin a stitch in
  58. time begin do not tie resume your shoe in a watermelon patch resume saves nine
  59. resume for all good men to come to the aid of their part))
Advertisement
Add Comment
Please, Sign In to add comment