[plt-scheme] Some fine distinctions

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue May 12 16:40:24 EDT 2009

On May 12, 2009, at 4:18 PM, wooks wrote:

> Individually I think I know what they are but I would have a tough
> time if asked to distinguish.
>
> Currying vs Partial evaluation.
>
> Tail recursion vs Accumulative recursion.

A function that uses an accumulator doesn't have to be in tail- 
recursive shape.

An accumulator is an 'extra' parameter that keeps track of some  
information between the "original" argument and the "current" one.  
This is easier to explain with a small fragment:

  ;; f : S -> T
  (define (f s0)
    ;; f-accu: S AccuType -> T
    ;; accumulator: a keeps track of all ... between s0 and s
    (define (f-accu s a)
      ... (f-accu (selector s) (combine (other-selector s) a)) ... )
    (f-accu s0 NULL_A))

If S is a list type, then s0 is the head of the list and s is  
somewhere in the middle.

NULL_A is usually some "identity" for combine, because in the  
beginning s == s0.

-- Matthias



Posted on the users mailing list.