Skip to content

Instantly share code, notes, and snippets.

@horus
Created January 10, 2011 02:59
Show Gist options
  • Select an option

  • Save horus/772282 to your computer and use it in GitHub Desktop.

Select an option

Save horus/772282 to your computer and use it in GitHub Desktop.
(defun add-at (a l pos)
(if (= pos 0)
(cons a l)
(cons (car l) (add-at a (rest l) (1- pos)))))
(defun insert-everywhere/in-a-word (char word)
(loop for position from 0 to (length word)
collecting (add-at char word position)))
(defun insert-in-all (char word)
(if (null word)
(list char)
(append (list char (car word)) (insert-in-all char (rest word)))))
---
CL-USER 38 > (INSERT-EVERYWHERE/IN-A-WORD 'a '(t e s t))
((A T E S T) (T A E S T) (T E A S T) (T E S A T) (T E S T A))
---
CL-USER 56 > (insert-in-all 'a '(t e s t))
(A T A E A S A T A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment