I found this code on stackoverflow (from Rainer Joswig):
(defun listFormat ()
(cl-labels ((place-index (idx l)
(if (null l)
nil
(append (list (first l)) (list idx)
(place-index (+ idx 1) (rest l))))))
(place-index 1 l))))
and I changed it by adding a let
form and cl-labels
:
(defun listFormat ()
(let ((l '(a b c d)))
(cl-labels ((place-index (idx l)
(if (null l)
nil
(append (list (first l)) (list idx)
(place-index (+ idx 1) (rest l))))))
(place-index 1 l))))
Is this a good practice? In the code I'm working on I need to establish variables with let
, then do a recursive function, i.e., I don't want the stuff inside the let
to be repeated on each recursion. I'm wondering if there is a way to combine this under cl-letf
. I try this, but it's not liking it:
(defun listFormat ()
(cl-letf ((l '(a b c d))
(place-index (idx l)
(if (null l)
nil
(append (list (first l)) (list idx)
(place-index (+ idx 1) (rest l))))))
(place-index 1 l)))
complaining of void function idx
. So, is there a way to combine let
content that shouldn't be resursed with an inner recursion function?