Regarding the following code
;; ANSI CL - p37 ;; Run length encoding: expansion ;; > (uncompress '((3 1) 0 1 (4 0) 1)) ;; (1 1 1 0 1 0 0 0 0 1) (defun uncompress (lst) (if (null lst) nil (let ((elt (car lst)) ;  (rest (uncompress (cdr lst)))) ;  (if (consp elt) (append (apply #'list-of elt) rest) ;  (cons elt rest))))) ;  (defun list-of (n elt) (if (zerop n) nil (cons elt (list-of (- n 1) elt)))) ;;  the compressed form, whether atom or list. ;;  uncompress the rest. recursion happens here. curious. ;;  compressed form, so expand it, & append to uncompressed rest. ;;  not a compressed form, so just cons it.
Left to my own devices, I would have written
uncompress like so
;; How my intuition would have said to write it, with the recursive ;; calls made where their results are used: (defun uncompress (lst) (if (null lst) nil (let ((elt (car lst))) (if (consp elt) (append (apply #'list-of elt) (uncompress (cdr lst))) (cons elt (uncompress (cdr lst)))))))
Computing the value of
rest in the
let in the first example appears to alter the path of the recursion. Is that correct? Or are
let forms merely substituted into later code where they are used?