Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. (defun extract-integers (string)
  2. (loop
  3. :with integer
  4. :with end := 0
  5. :for start := (position-if (function digit-char-p) string :start end)
  6. :while start
  7. :do (setf (values integer end) (parse-integer string :start start :junk-allowed t))
  8. :collect integer))
  9.  
  10. (defun test/extract-integers ()
  11. (assert (equal (extract-integers "123abc456")
  12. '(123 456)))
  13. (assert (equal (extract-integers "foo")
  14. '()))
  15. (assert (equal (extract-integers "1 2 3 4")
  16. '(1 2 3 4)))
  17. (assert (equal (extract-integers "1234")
  18. '(1234)))
  19. :success)
  20.  
  21. (test/extract-integers) ; --> :success
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement