I tried reversing a list in scheme using the most basic concept I had about cons,cdr,car.
Here,l-orig
is the list to be reversed and l-count
acts as a counter.
My code goes here:
(define (rev l-orig l-count)
(
if (null? l-count)
(cons l-orig '())
(rev (cons (cdr l-orig) (car l-orig)) (cdr l-count))
)
)
(display (rev '(1 2 3 4 5) '(1 1 1 1 1)))
And the output is (((2 3 4 5) . 1))
Honestly speaking, I am a beginner in lisp and I need a simple help here.
If I intend to use this method, can anyone suggest me a correct way of doing it?