; File: neighbors.scm ; Title: Check neighbors of an element in a list ; Please enter list? (a b c d) ; Search for? b ; b is a member Next is c Before is a ; Continue(y/n)? y ; Please enter list?: (a b c d) ; Search for? a ; a is a member Next is b Before is () ; Continue(y/n)? n ; Goodbye! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (start) (program) (if (yesorno) (start) (bye)) ) (define (next w l) (cond ((null? l) #f) ((equal? w (car l)) (if (null? (cdr l)) () (cadr l))) (#t (next w (cdr l))) )) (define (before w l) (next w (reverse l)) ) (define (program) (let((L (readList))(a 0)) (display "List is: ")(display L) (display "Search for? ")(set! a (read)) (cond ((member a L) (display a) (display " is a member") (display "\tNext is ") (display (next a L)) (display "\tBefore is ") (display (before a L))) (#t (display "not in the list")) ))) (define (readList) (display "Please enter list? ") (let ((L (read))) (if (not (list? L)) (readList) L); check good input: if L is not a list, ask again )) (define (yesorno) (display "\nContinue(y/n)? ") (member (read) '(y Y yes Yes da DA OK ok si oui)) ) (define (bye)(display "Goodbye!\n") ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (start)