[racket] Generating Tuples from List

From: Adam Shaw (adamshaw at cs.uchicago.edu)
Date: Wed Feb 29 22:32:33 EST 2012

(define (tuples xs n)
  (if (<= n 0)
      (list empty)
      (foldr append empty (map (λ (t) (map (λ (x) (cons x t)) xs)) (tuples xs (sub1 n))))))


On Feb 29, 2012, at 8:52 PM, Ashok Bakthavathsalam wrote:

> Again, trying to mimic something available in Mathematica (Tuples - Wolfram Mathematica 8 Documentation http://bit.ly/AgsIym).
> How can this be accomplished in Racket? Here's an example from the Mathematica documentation.
> All possible 3-tuples of  and :
> In[1]:=	
> 
> Out[1]=	
> 
> No, this is not homework. So, would appreciate code if available. 
> 
> Thanks,
> 
>   % ashok
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120229/51064759/attachment.html>

Posted on the users mailing list.