Scheme - Cartesian product with 'map'?
<p>I am trying to write a function that returns the cartesian product of 2 sets (lists) with the help of the 'map' function and I want each pair of elements in the returned list to be a vector.</p>

<pre><code>(cartesian-product '(1 2 3) '(a b))

'(#(3 a) #(3 b) #(2 a) #(2 b) #(1 a) #(1 b))
</code></pre>

<p>My initial idea was to make a separate procedure that makes a vector out element c (constant) in set 2 and element n in set 1 where element n changes for each iteration and then proceed to map this separate function with set 2. So for example, if I use the above lists (in the code sample) I would get 3 different vectors from this separate function:</p>

<pre><code>#'(a 1) #'(a 2) #'(a 3)
</code></pre>

<p>And when using map on this I would get the result:</p>

<pre><code>'(#'(a 1) #'(a 2) #'(a 3) #'(b 1) #'(b 2) #'(b 3))
</code></pre>

<p>But I realized that I would instead get a result that looks something like this:</p>

<pre><code>'((#'(a 1) #'(a 2) #'(a 3)) (#'(b 1) #'(b 2) #'(b 3)))
</code></pre>

<p>because the separate function has to be recursive and it would have to return a list when finished.</p>

<p>Now I am back to square one and I am out of ideas. Help please...
Should mention that this is a school assignment and I am not allowed to use any predefined functions except for simple ones like:</p>

<pre><code>cdr,car,cons,map etc
</code></pre>

<p>Try to keep it as basic as possible. I have only been using Scheme for like a month so go easy on me :)</p>