Sujet : Cprod (Cartesian Product) in Lisp (or Scheme) De : HenHanna (at) *nospam* devnull.tb (HenHanna) Groupes :comp.lang.lispcomp.lang.scheme Date : 21. May 2024, 21:18:52 Autres entêtes Organisation : A noiseless patient Spider Message-ID :<v2is2s$ndjr$4@dont-email.me> User-Agent : Mozilla Thunderbird
How would you write this in Lisp (or Scheme) ? in Python... (writing this out: itertools.product([0, 1], repeat=N ) The value can be a list or a Tuple. cprod([0, 1], 1) => ((0) (1)) cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) This works: def cprod(x, c): if c==1: return [[i] for i in x] Sub= cprod(x, c-1) return [i for F in x for i in [[F]+R for R in Sub]] ---------- Is there another (better) way to write [F]+R ??? it seems odd, compared to CONS in Lisp Other ways to improve it?