fork download
  1. ;; (import (chicken string))
  2. (define (product . lists)
  3. (define (prod xs ys)
  4. (reverse (foldl (lambda (acc x) (foldl (lambda (acc y) (cons (list x y) acc)) acc ys)) '() xs)))
  5. (map flatten (foldl prod '(()) lists)))
  6. (define (repeat x n)
  7. (define (aux acc n)
  8. (if (<= n 0)
  9. acc
  10. (aux (cons x acc) (- n 1))))
  11. (aux '() n))
  12. (define (f s n)
  13. (apply product (repeat (string-chop s 1) n)))
  14. (print (f "ABC" 0))
  15. (print (f "ABC" 1))
  16. (print (f "ABC" 2))
  17. (print (f "ABC" 3))
  18.  
Success #stdin #stdout 0.01s 7808KB
stdin
Standard input is empty
stdout
(())
((A) (B) (C))
((A A) (A B) (A C) (B A) (B B) (B C) (C A) (C B) (C C))
((A A A) (A A B) (A A C) (A B A) (A B B) (A B C) (A C A) (A C B) (A C C) (B A A) (B A B) (B A C) (B B A) (B B B) (B B C) (B C A) (B C B) (B C C) (C A A) (C A B) (C A C) (C B A) (C B B) (C B C) (C C A) (C C B) (C C C))