1
0

utils.lisp 694 B

12345678910111213141516171819
  1. (in-package #:chatikbot)
  2. (defun replace-all (string part replacement &key (test #'char=))
  3. "Returns a new string in which all the occurences of the part
  4. is replaced with replacement."
  5. (with-output-to-string (out)
  6. (loop with part-length = (length part)
  7. for old-pos = 0 then (+ pos part-length)
  8. for pos = (search part string
  9. :start2 old-pos
  10. :test test)
  11. do (write-string string out
  12. :start old-pos
  13. :end (or pos (length string)))
  14. when pos do (write-string replacement out)
  15. while pos)))
  16. (defmacro aget (key alist)
  17. `(cdr (assoc ,key ,alist :test #'equal)))