sva36863.scm 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ;; From Savannah bug #36863 "then clause grows stack with no else clause"
  2. (define (first (iterable ::java.lang.Iterable))
  3. (let ((f (lambda (x) #t))
  4. (iter (iterable:iterator)))
  5. (let loop ()
  6. (if (iter:hasNext)
  7. (let ((item (iter:next)))
  8. (if (f item)
  9. item
  10. (loop)))
  11. #f))))
  12. ;; These are variations, with different bodies for the function f.
  13. (define (no-match (iterable ::java.lang.Iterable))
  14. (let ((f (lambda (x) #f))
  15. (iter (iterable:iterator)))
  16. (let loop ()
  17. (if (iter:hasNext)
  18. (let ((item (iter:next)))
  19. (if (f item)
  20. item
  21. (loop)))
  22. #f))))
  23. (define (odd-match (iterable ::java.lang.Iterable))
  24. (let ((f (lambda (x) (odd? x)))
  25. (iter (iterable:iterator)))
  26. (let loop ()
  27. (if (iter:hasNext)
  28. (let ((item (iter:next)))
  29. (if (f item)
  30. item
  31. (loop)))
  32. #f))))
  33. (format #t "~s.~%" (first (vector 3 4 5)))
  34. ;; Output: 3.
  35. (format #t "~s.~%" (no-match (vector 3 4 5)))
  36. ;; Output: #f.
  37. (format #t "~s.~%" (odd-match (vector 2 4 7 9)))
  38. ;; Output: 7.