#lang racket

; now accumulate in reverse order, since we keep appending to end anyway.
; this eliminates the append and last operations

(define prefix-list-r
      (lambda (op L-accum L-todo)
        (if (null? L-todo)
            ; adjust the result into proper order
            (reverse L-accum)

            ; add the next element to the end and recurse
            (prefix-list-r op
                ; new L-accum
                (cons 
                  (op (first L-accum) (first L-todo))
                  L-accum)
                ; shorter todo
                (rest L-todo))
            )
        )
      )

(define prefix-list
  (lambda (op L)
    (prefix-list-r op (list (first L)) (rest L))))