Created
January 10, 2011 02:59
-
-
Save horus/772282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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