common-lisp Recursion Recursively print the elements of a list


Example

;;Recursively print the elements of a list
(defun print-list (elements)
    (cond
        ((null elements) '()) ;; Base case: There are no elements that have yet to be printed. Don't do anything and return a null list.
        (t
            ;; Recursive case
            ;; Print the next element.
            (write-line (write-to-string (car elements)))
            ;; Recurse on the rest of the list.
            (print-list (cdr elements))
        )
    )
)

To test this, run:

(setq test-list '(1 2 3 4))
(print-list test-list)

The result will be:

1
2
3
4