diff --git a/main.rkt b/main.rkt index 6904088..236209e 100644 --- a/main.rkt +++ b/main.rkt @@ -114,13 +114,21 @@ [else (tail-call lst)])) -(define (scanl proc lst) - (foldl - (λ (val acc) - (append acc (list (proc val (last acc))))) - (list (first lst)) - (rest lst))) - +(define scanl + (case-lambda + [(proc lst) + (scanl proc (car lst) (cdr lst))] + [(proc seed lst) + (let loop ([acc (list seed)] + [val seed] + [rest lst]) + (if (empty? rest) + (reverse acc) + (let ([next (proc val (car rest))]) + (loop (cons next acc) + next + (cdr rest)))))])) + (define (scanr proc lst) (foldl