'Not retrieving the character at an index of a list correctly?
I am writing a program that recursively iterates through a list, provided the index of the current character and a list of characters. However, when I run the following program:
(defun printAllElementsRecursively (index providedList)
(if (>= index (length providedList))
(return-from printAllElementsRecursively NIL)
)
(defvar currCharacter (nth index providedList))
(print (format nil "Character at index ~a: ~a" index currCharacter))
(printAllElementsRecursively (+ index 1) providedList)
)
(printAllElementsRecursively 0 '(A B B A))
I get the following output:
"Character at index 0: A"
"Character at index 1: A"
"Character at index 2: A"
"Character at index 3: A"
This seems strange, considering that the value of index does increment correctly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
