P02 (*) 获取列表的倒数第二个元素

Example:

sash> (last_but_one '(a b c d))
sash> c

(1)跟P01类似,只多判断一个条件,即如果列表里只有一个元素,则返回#t

(define last_but_one
    (lambda (ls)
      (if (null? ls)
          (raise 'not-found)
          (let ([lr (cdr ls)])
            (cond [(null? lr) (raise 'not-found)] [(null? (cdr lr)) 

你可能感兴趣的:(Scheme,Ninety-Nine,Scheme,Problems,lambda,lisp,scheme)