I am new to Lisp (and functional programming, really), and just finished the below code that works great.
However, I am told that I should "treat setf as if there were a tax on its use". And yet this simple function has it twice.
How would I go about removing them (without turning my optional argument in to a key)? Also, if you see that I'm making some other non-related mistakes, please let me know.
- Code: Select all
; by Will Fitzgerald
(defun strcat (&rest strings)
(apply 'concatenate 'string strings))
; by me
(defun alternate (text &optional tchar)
"Return the string with every other character replaced"
(if tchar () (setf tchar "$"))
(let ((out ""))
(dotimes (iter (length text) out)
(setf out (strcat out
(if (= 1 (mod iter 2)) tchar
(subseq text iter (+ iter 1))))))))