I'm trying to write a function that creates the permutation of a list using just the basic list constructs (cons, empty, first, rest). I'm thinking of inserting the first value of the list everywhere in the recursive call of the rest of the list, but I'm having some trouble with my base case.
My code:
(define (permutation lst)
(cond
[(empty? lst) (cons empty empty)]
[else (insert_everywhere (first lst) (permutation (rest lst)))]))
(permutation (list 1 2)) gives me (list 1 2 empty 2 1 empty). Is there anything I can do to create a placeholder (such as empty) between the different combinations but not have the program interpret the placeholder as an element in the list?
Is my base case right?
Thanks!