[plt-scheme] Why no zip in "list.ss"?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Dec 27 13:59:35 EST 2006

> I could have sworn that zip was included in list.ss, but apparently not. 
> Certainly, it seems a natural.

Hi Gregory,

Here's an alternative implementation that you might like:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define (zip l1 l2)
     (map list l1 l2))
>
> (zip '(1 2 3 4 5) '(one two three four five))
((1 one) (2 two) (3 three) (4 four) (5 five))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


But the ZIP function you're thinking of does exist in the SRFI-1 "list" 
library.  We can also say:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (require (only (lib "1.ss" "srfi") zip))
>
> (zip '(1 2 3 4 5)
        '(one two three four five))
((1 one) (2 two) (3 three) (4 four) (5 five))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


See:

  http://download.plt-scheme.org/doc/360/html/srfi/srfi-1.html
  http://download.plt-scheme.org/doc/360/html/r5rs/r5rs-Z-H-9.html#%25_idx_580

for more details.  Good luck!


Posted on the users mailing list.