Note
This is not a REBOL related question. You can answer it in any language.
Background
The REBOL language supports the creation of domain languages ββknown as βdialectsβ in the REBOL language. I created such a dialect for understanding lists that are not supported in REBOL.
To understand the list, you need a good Cartesian product algorithm.
Problem
I used metaprogramming to solve this problem by dynamically creating and then executing a sequence of nested statements foreach. It works beautifully. However, since it is dynamic, the code is not very readable. REBOL is not very good recursive. He quickly runs out of stack space and crashes. So a recursive solution is out of the question.
In general, I want, if possible, to replace my metaprogramming with a readable, non-recursive, built-in algorithm. The solution can be in any language if I can reproduce it in REBOL. (I can read almost any programming language: C #, C, C ++, Perl, Oz, Haskell, Erlang, whatever.)
, , "", .