Re: LAST CALL for SRFI-113, Sets and bags John Cowan 22 Aug 2014 20:26 UTC

Kevin Wortman scripsit:

> (define (cartesian . sets)
>   (fold-right (lambda (set tuples)
>         (append-map! (lambda (element)
>                    (map (cute cons element <>) tuples))
>                  set))
>           '(())
>           sets))

This is the same algo that I worked out walking to work today, except
that I reversed "sets" in advance (it's safe to use reverse!) and did
a left fold, because left folds are tail-recursive in eager languages.

--
John Cowan          http://www.ccil.org/~cowan        xxxxxx@ccil.org
You know, you haven't stopped talking since I came here. You must
have been vaccinated with a phonograph needle.
        --Rufus T. Firefly