Advertisement
Guest User

Untitled

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