67.sld 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. (define-library (srfi 67)
  2. (export
  3. </<=?
  4. </<?
  5. <=/<=?
  6. <=/<?
  7. <=?
  8. <?
  9. =?
  10. >/>=?
  11. >/>?
  12. >=/>=?
  13. >=/>?
  14. >=?
  15. >?
  16. boolean-compare
  17. chain<=?
  18. chain<?
  19. chain=?
  20. chain>=?
  21. chain>?
  22. char-compare
  23. char-compare-ci
  24. compare-by<
  25. compare-by<=
  26. compare-by=/<
  27. compare-by=/>
  28. compare-by>
  29. compare-by>=
  30. complex-compare
  31. cond-compare
  32. debug-compare
  33. default-compare
  34. if-not=?
  35. if3
  36. if<=?
  37. if<?
  38. if=?
  39. if>=?
  40. if>?
  41. integer-compare
  42. kth-largest
  43. list-compare
  44. list-compare-as-vector
  45. max-compare
  46. min-compare
  47. not=?
  48. number-compare
  49. pair-compare
  50. pair-compare-car
  51. pair-compare-cdr
  52. pairwise-not=?
  53. rational-compare
  54. real-compare
  55. refine-compare
  56. select-compare
  57. symbol-compare
  58. vector-compare
  59. vector-compare-as-list
  60. bytevector-compare
  61. bytevector-compare-as-list
  62. )
  63. (import
  64. (scheme base)
  65. (scheme case-lambda)
  66. (scheme char)
  67. (scheme complex)
  68. (srfi 27))
  69. (include "67.upstream.scm")
  70. (begin
  71. (define (bytevector-compare bv1 bv2)
  72. (let ((len1 (bytevector-length bv1))
  73. (len2 (bytevector-length bv2)))
  74. (cond
  75. ((< len1 len2) -1)
  76. ((> len1 len2) +1)
  77. (else
  78. (let lp ((i 0))
  79. (if (= i len1)
  80. 0
  81. (let ((b1 (bytevector-u8-ref bv1 i))
  82. (b2 (bytevector-u8-ref bv2 i)))
  83. (cond
  84. ((< b1 b2) -1)
  85. ((> b1 b2) +1)
  86. (else
  87. (lp (+ 1 i)))))))))))
  88. (define (bytevector-compare-as-list bv1 bv2)
  89. (let ((len1 (bytevector-length bv1))
  90. (len2 (bytevector-length bv2)))
  91. (let lp ((i 0))
  92. (cond
  93. ((or (= i len1) (= i len2))
  94. (cond ((< len1 len2) -1)
  95. ((> len1 len2) +1)
  96. (else 0)))
  97. (else
  98. (let ((b1 (bytevector-u8-ref bv1 i))
  99. (b2 (bytevector-u8-ref bv2 i)))
  100. (cond
  101. ((< b1 b2) -1)
  102. ((> b1 b2) +1)
  103. (else
  104. (lp (+ 1 i))))))))))
  105. ))