sva36039.scm 514 B

12345678910111213141516171819202122
  1. (module-export find)
  2. (define (find x list)
  3. (find-if list
  4. (lambda (y)
  5. (equal? x y))
  6. #f))
  7. (define (find-if (i ::java.lang.Iterable) test default)
  8. (let ((iter (invoke i 'iterator))
  9. (found #f))
  10. (do ()
  11. ((or found (not (invoke iter 'has-next))))
  12. (let ((e (invoke iter 'next)))
  13. (when (test e)
  14. (set! found #t)
  15. (set! default e))))
  16. default))
  17. (format #t "~s ~s~%" (find 3 #(8 7 13 2)) (find 13 #(8 7 13 2)))
  18. ;; Output: #f 13