Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. (defun split (separator splittee)
  2. (let ((next-index (position separator splittee)))
  3. (if next-index
  4. (cons (subseq splittee 0 next-index) (split separator (subseq splittee (1+ next-index))))
  5. (list splittee))))
  6.  
  7. (defun replace-all (replacand replacee replacor)
  8. (let ((next-index (position replacand replacee)))
  9. (if next-index
  10. (concatenate 'string (subseq replacee 0 next-index) replacor (replace-all replacand (subseq replacee (1+ next-index)) replacor))
  11. replacee)))
  12.  
  13. (defun where-found (sought-letter the-string to-do-onroute to-do-on-leaf)
  14. (let ((next-index (position sought-letter the-string)))
  15. (if next-index
  16. (apply to-do-onroute
  17. (list (subseq the-string 0 next-index)
  18. (subseq the-string (1+ next-index))))
  19. (apply to-do-on-leaf (list the-string)))))
  20.  
  21. (defun split (separator splittee)
  22. (where-found separator splittee
  23. (lambda (pre-string post-string) (cons pre-string (split separator post-string)))
  24. (lambda (leaf-string) (list leaf-string))))
  25.  
  26. (defun replace-all (to-be-replaced-string the-patient-string the-replacement-string)
  27. (where-found to-be-replaced-string the-patient-string
  28. (lambda (pre-string post-string)
  29. (format t "pre: ~a post: ~a the-replacement-string: ~a ~%" pre-string post-string the-replacement-string)
  30. (concatenate 'string pre-string the-replacement-string (replace-all to-be-replaced-string post-string the-replacement-string)))
  31. (lambda (leaf-string) leaf-string)))
  32.  
  33. (format t "the cat is here: ~a ~%" (replace-all #Space "the cat is here" ""))
  34. (format t "the cat is here: ~a ~%" (split #Space "the cat is here"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement