I'm trying to reverse a list in Scheme, but I can only use define, car, cdr, list?, null?, if, cond, cons, display, begin, and any operators. I cannot use append, loops (must be pure recursion), lambda and any other functions that I have not mentioned. I'm also not allowed to use helper functions. Everything should be in one function.
It's been hours now and I've tried multiple solutions and I still cannot solve this. This is the closest solution that I got:
(define (my-reverse2 lis)
(if (null? (cdr lis)) lis
(cons (my-reverse2 (cdr lis)) (cons (car lis) '()))))
And this is the output:
> (my-reverse2 '(3 2 1))
Output: (list (list (list 1) 2) 3)
The output should be something like (1 2 3)
. How should I proceed?