All pastes #936072 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-10 02:46 UTC
rendered paste body
1.
(define collectEvens
 (lambda (L)
  (cond ((null? L) '())
     ((even? (car L)) (cons (car L) (collectEvens (cdr L))))
     (else (collectEvens (cdr L))))))
2.
(define replace-nth
  (lambda (k a r)
    (cond ((null? r) '())
          ((= k 1) (cons a (replace-nth (- k 1) a (cdr r))))
          (else (cons (car r) (replace-nth (- k 1) a (cdr r)))))))

3.
(define cons-to-end
  (lambda (n L)
    (cond ((null? L) (cons n '()))
          (else (cons (car L) (cons-to-end n (cdr L)))))))