[taos-glug] choice of name "flatmap"?

  • From: Philip Ansteth <pansteth@xxxxxxxxxxx>
  • To: taos-glug@xxxxxxxxxxxxx
  • Date: Wed, 20 Aug 2003 17:25:19 -0600

Jon or anybody,

Whence the name "flatmap"?  Or rather, the "flat" part of the
name?  It's in the section "Nested Mappings."   Why do they call
it that?   (It's in Section 2.2.3)

The authors say

> (accumulate append
>             nil
>             (map (lambda (i)
>                    (map (lambda (j) (list i j))
>                         (enumerate-interval 1 (- i 1))))
>                  (enumerate-interval 1 n)))
> 
> The combination of mapping and accumulating with append is so common
> in this sort of program that we will isolate it as a separate procedure:
> 
> (define (flatmap proc seq)
>   (accumulate append nil (map proc seq)))
> 


A paragraph or so later, they write:
> 
> (define (prime-sum-pairs n)
>   (map make-pair-sum
>        (filter prime-sum?
>                (flatmap
>                 (lambda (i)
>                   (map (lambda (j) (list i j))
>                        (enumerate-interval 1 (- i 1))))
>                 (enumerate-interval 1 n)))))
> 


As far as I can tell, isolating flatmap as a separate
procedure boils down to removing the leading "(accumulate append nil . . ."

Such a removal is, I suppose, a worthwhile thing to do, if the
combination "calculate append nil" is common.   But I don't understand
the "flat" in "flatmap."

(Remeber that Guile users, at least, use '() in place of null.)

Philip


Other related posts:

  • » [taos-glug] choice of name "flatmap"?