I am trying to answer a scheme question, for a part of this question I have to make a list of lists:
(define (join a b (result '()))
(cons (list a b) result))
So I am taking in two characters, and placing them in a list, then I need to place each sublist into a list of lists, this function is being called recursively with two characters each time, so it is supposed to work like this:
join 1 4
=> ((1 4))
join 2 5
=> ((1 4) (2 5))
join 3 6
=> ((1 4) (2 5) (3 6))
However, I am getting ((3 6) (2 5) (1 4))
, so the elements need to be reversed, I tried reversing my cons
function to (cons result (list a b))
but then I get (((() 1 4) 2 5) 3 6)
, how can I get the list the right way around, or is there an easier way to do what I'm doing?