simply scheme 第十四章 练习

14.1

Keep

(define (remove-once wd sent)

  (cond((empty? sent)'())

       ((equal? wd(first sent))

        (se (bf sent)))

       (else (se (first sent)(remove-once wd(bf sent))))))

14.2

Every

(define(up wd)

  (if(empty? wd)

     '()

     (se (up (bl wd))wd)))

14.3

(define (remdup sent)

  (cond((empty? sent)

        '())

       ((if(in? (first sent)(bf sent))

        (se (remdup(bf sent)))

        (se (first sent)(remdup (bf sent)))))))

(define (in? wd sent)

  (if(empty? sent)

     #f

     (if(equal? wd (first sent))

        #t

        (in? wd (bf sent)))))

14.4

(define (odds sent)

  (if(or(empty? sent)(=(count sent)1))

     (first sent)

     (se (first sent)(odds (bf(bf sent))))))

14.5

(define (letter-count sent)

  (if(empty? sent)

     0

     (+ (count (first sent))(letter-count(bf sent)))))

14.6

(define (member? wd sent)

  (if(empty? sent)

     #f

     (if(equal? wd (first sent))

        #t

        (member? wd (bf sent)))))

14.7

(define (differences sent)

  (if(=(count sent)2)

     (-(first(bf sent))(first sent))

     (se (-(first(bf sent))(first sent))

         (differences (bf sent)))))

14.8

(define (expand sent)

  (if(empty? sent)

     '()

     (if(number? (first sent))

        (se (repeat(-(first sent)1)(first(bf sent)))

            (expand (bf sent)))

        (se (first sent)(expand(bf sent))))))

(define (repeat num wd)

  (if(= num 0)

     '()

     (se wd (repeat (- num 1)wd))))

14.9

(define (l wd sent)

  (if(empty? sent)

     2

     (if(not(equal? wd (first sent)))

        (+ 1 (l wd (bf sent)))

        (+ 1))))

(define (location wd sent)

  (if(< (count sent)(l wd sent))

     #f

     (l wd sent)))

14.10

(define (count-adjacent-duplicates sent)

  (if(=(count sent)1)

     0

     (if(equal? (first sent)(first(bf sent)))

        (+ 1 (count-adjacent-duplicates (bf sent)))

        (+ (count-adjacent-duplicates (bf sent))))))

14.11

(define (remove-adjacent-duplicates sent)

  (if(=(count sent)1)

     (first sent)

     (if(equal? (first sent)(first(bf sent)))

        (se (remove-adjacent-duplicates (bf sent)))

        (se (first sent)(remove-adjacent-duplicates(bf sent))))))

14.12

(define (progressive-squares? sent)

  (if(=(count sent)1)

     #t

     (if(=(first(bf sent))(*(first sent)(first sent)))

        (progressive-squares? (bf sent))

        #f)))

14.13

14.14

(define (same-shape? s1 s2)

  (if(=(count s1)(count s2))

     (if(empty? s1)

        #t

        (if(=(count(first s1))(count(first s2)))

           (same-shape?(bf s1)(bf s2))

           #f))

     #f))

14.15

(define (merge s1 s2)

  (if(and(empty? s1)(empty? s2))

     '()

     (cond((empty? s1)s2)

          ((empty? s2)s1)

          ((< (first s1)(first s2))

              (se (first s1)(merge(bf s1)s2)))

          (else

              (se (first s2)(merge(bf s2)s1))))))

14.16

I have no idea about vowel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值