[plt-scheme] "Zipping" two lists?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Wed Feb 22 13:33:52 EST 2006

Does (map list my-list1 my-list2) do what you want?

On 2/22/06, Greg Woodhouse <gregory.woodhouse at sbcglobal.net> wrote:
> Does Scheme provide a standard way to do this? I wrote a little ad hoc
> function, but it seems that this ought to be common enough an operation
> to have a standard solution.
>
> ;;zip two list (e.g., (zip (1 2) (3 4)) is ((1 3) (2 4)))
> ;;(list, list) -> list
> (define (zip ls1 ls2)
>   (if (equal? (length ls1) (length ls2))
>       (if (null? ls1) '()
>           (cons (list (car ls1) (car ls2))
>                 (zip (cdr ls1) (cdr ls2))))))
>
> ===
> Gregory Woodhouse  <gregory.woodhouse at sbcglobal.net>
> "All truth passes through three stages: First, it is ridiculed.
> Second, it is violently opposed. Third, it is accepted as
> being self-evident."
> --Arthur Schopenhauer
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


--
Carl Eastlund
"Cynical, but technically correct."


Posted on the users mailing list.