sicp practice 1.12

#lang racket
(define (sum-lst lst)
  (let loop ((lst lst) (accum '()) (prev 0))
    (cond
    ((empty? lst) (reverse (cons 1 accum)))
    (else (loop (cdr lst) (cons (+ (car lst) prev) accum) (car lst))))))

(sum-lst '(1))输出'(1 1)
(sum-lst '(1 1)输出'(1 2 1)

这题是为了输出帕斯卡三角

你可能感兴趣的:(SICP)