summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Daphne Preston-Kendal 2022-11-26 13:00:05 +0100
committerGravatar Daphne Preston-Kendal 2022-11-26 13:00:05 +0100
commitc25e65bae96d6d5c26b0d9e8af96e8dcdbdaf99f (patch)
treec267d5839f1e3b77d8c903952dd573ffeae1cb31
parentSpecify base cases and behaviours of each comparator function (diff)
parentPublish third draft. (diff)
Merge branch 'master' of https://github.com/scheme-requests-for-implementation/srfi-228
Diffstat (limited to '')
-rw-r--r--README.org8
-rw-r--r--index.html107
-rw-r--r--srfi-228-test.scm83
-rw-r--r--srfi-228.html7
-rw-r--r--srfi/228.sld7
-rw-r--r--srfi/srfi-228.scm (renamed from srfi/composing-comparators.scm)3
6 files changed, 126 insertions, 89 deletions
diff --git a/README.org b/README.org
index 33acebc..5232935 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,5 @@
-* SRFI 228: A further comparator library
+
+* SRFI 228: Composing Comparators
** by Daphne Preston-Kendal
@@ -6,15 +7,14 @@
keywords: [[https://srfi.schemers.org/?keywords=comparison][Comparison]]
-This repository hosts [[https://srfi.schemers.org/srfi-228/][SRFI 228]]: A further comparator library, a [[https://srfi.schemers.org/][Scheme Request for Implementation]].
+This repository hosts [[https://srfi.schemers.org/srfi-228/][SRFI 228]]: Composing Comparators, a [[https://srfi.schemers.org/][Scheme Request for Implementation]].
This SRFI is in /draft/ status.
-
+See also [[/srfi-128/][SRFI 128: Comparators (reduced)]] and [[/srfi-162/][SRFI 162: Comparators sublibrary]].
The full documentation for this SRFI can be found in the [[https://srfi.schemers.org/srfi-228/srfi-228.html][SRFI Document]].
If you'd like to participate in the discussion of this SRFI, or report issues with it, please [[https://srfi.schemers.org/srfi-228/][join the SRFI-228 mailing list]] and send your message there.
Thank you.
-
[[mailto:srfi-editors@srfi.schemers.org][The SRFI Editors]]
diff --git a/index.html b/index.html
index 8e4a1ae..d6b8c75 100644
--- a/index.html
+++ b/index.html
@@ -1,81 +1,32 @@
<!DOCTYPE html>
<html>
- <head>
- <title>A further comparator library</title>
- <link href="/admin.css" rel="stylesheet">
- <link href="/list.css" rel="stylesheet">
- <link href="/favicon.png" rel="icon" sizes="192x192" type="image/png">
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <script type="text/x-mathjax-config">
- MathJax.Hub.Config({
- tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
- });
- </script>
- <script crossorigin="anonymous" integrity=
- "sha384-Ra6zh6uYMmH5ydwCqqMoykyf1T/+ZcnOQfFPhDrp2kI4OIxadnhsvvA2vv9A7xYv" src=
- "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
- type="text/javascript"></script>
- </head>
+ <head>
+ <title>Composing Comparators</title>
+ <link href="/admin.css" rel="stylesheet">
+ <link href="/list.css" rel="stylesheet">
+ <link href="/favicon.png" rel="icon" sizes="192x192" type="image/png">
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
+ <script crossorigin="anonymous" integrity="sha384-Ra6zh6uYMmH5ydwCqqMoykyf1T/+ZcnOQfFPhDrp2kI4OIxadnhsvvA2vv9A7xYv" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head>
+ <body>
+ <h1>SRFI 228: Composing Comparators</h1>
+ <p class="authors">by Daphne Preston-Kendal</p>
+ <p class="based-on"></p>
+ <p class="status">status: <em>draft</em> (2021-08-28)</p>
+ <p class="keywords">keywords: <a href="https://srfi.schemers.org/?keywords=comparison">Comparison</a></p><span class="see-also">See also <a href="/srfi-128/">SRFI 128: Comparators (reduced)</a> and <a href="/srfi-162/">SRFI 162: Comparators sublibrary</a>.</span>
+ <ul class="info">
+ <li><a href="srfi-228.html">The SRFI Document</a></li>
+ <li><a href="https://srfi-email.schemers.org/srfi-228/">Discussion Archive</a></li>
+ <li><a href="https://github.com/scheme-requests-for-implementation/srfi-228">Git repo (on GitHub)</a></li>
+ <li><a href="mailto:srfi-228@srfi.schemers.org">srfi-228@<span class="antispam">nospam</span>srfi.schemers.org (subscribers only)</a></li>
+ <li><span class="firefox-column-workaround">
+ <form method="POST" action="https://www.simplelists.com/subscribe.php">
+ <div class="title">Subscribe to srfi-228 mailing list</div><input name="email" placeholder="email address" tabindex="1" type="email"><input name="name" placeholder="full name" tabindex="2" type="text">
+ <p><input id="sub-digest" name="digest" tabindex="3" type="checkbox" value="digest"><label for="sub-digest">daily digest?</label></p><input class="submit" name="submit" tabindex="4" type="submit" value="Subscribe to srfi-228"><input type="hidden" name="action" value="subscribe"><input type="hidden" name="list" value="srfi-228@srfi.schemers.org"></form></span></li>
+ <li><span class="firefox-column-workaround">
+ <form method="POST" action="https://www.simplelists.com/subscribe.php">
+ <div class="title">Unsubscribe from srfi-228 mailing list</div><input name="email" placeholder="email address" tabindex="5" type="email"><input class="submit" name="submit" tabindex="6" type="submit" value="Unsubscribe from srfi-228"><input type="hidden" name="action" value="unsubscribe"><input name="list" type="hidden" value="srfi-228@srfi.schemers.org"></form></span></li></ul>
+ <h2>Abstract</h2><p>Further procedures for defining <a href="https://srfi.schemers.org/srfi-128/">SRFI 128</a> comparators.
- <body>
- <h1>SRFI 228: A further comparator library</h1>
- <p class="authors">by Daphne Preston-Kendal</p>
- <p class="based-on"></p>
- <p class="status">status: <em>draft</em> (2021-08-28)</p>
- <p class="keywords">keywords: <a href="https://srfi.schemers.org/?keywords=comparison">Comparison</a></p>
-
- <ul class="info">
- <li><a href="srfi-228.html">The SRFI Document</a></li>
- <li><a href="https://srfi-email.schemers.org/srfi-228/">Discussion Archive</a></li>
- <li><a href="https://github.com/scheme-requests-for-implementation/srfi-228">Git repo (on Github)</a></li>
- <li>
- <a href="mailto:srfi-228@srfi.schemers.org">srfi-228@<span class="antispam">nospam</span>srfi.schemers.org (subscribers only)</a></li>
- <li>
- <span class="firefox-column-workaround">
- <form method="POST" action="https://www.simplelists.com/subscribe.php">
- <div class="title">Subscribe to srfi-228 mailing list</div>
- <input name="email"
- placeholder="email address"
- tabindex="1"
- type="email" >
- <input name="name"
- placeholder="full name"
- tabindex="2"
- type="text" >
- <p>
- <input id="sub-digest"
- name="digest"
- tabindex="3"
- type="checkbox"
- value="digest" >
- <label for="sub-digest">daily digest?</label></p>
- <input class="submit"
- name="submit"
- tabindex="4"
- type="submit"
- value="Subscribe to srfi-228" >
- <input type="hidden" name="action" value="subscribe">
- <input type="hidden" name="list" value="srfi-228@srfi.schemers.org"></form></a></li>
- <li>
- <span class="firefox-column-workaround">
- <form method="POST" action="https://www.simplelists.com/subscribe.php">
- <p class="title">Unsubscribe from srfi-228 mailing list</p>
- <input name="email"
- placeholder="email address"
- tabindex="5"
- type="email" >
- <input class="submit"
- name="submit"
- tabindex="6"
- type="submit"
- value="Unsubscribe from srfi-228" >
- <input name="action"
- type="hidden"
- value="unsubscribe" >
- <input name="list"
- type="hidden"
- value="srfi-228@srfi.schemers.org"></form></a></li></ul>
- <h2>Abstract</h2><p>Further procedures and syntax forms for defining <a href="https://srfi.schemers.org/srfi-128/srfi-128.html">SRFI 128</a> comparators, and for extracting comparison procedures similar to those defined for Scheme’s built-in types using them.
-
-<p>Best enjoyed in combination with <a href="https://srfi.schemers.org/srfi-162/srfi-162.html">SRFI 162</a>.</body></html> \ No newline at end of file
+<p>Best enjoyed in combination with <a href="https://srfi.schemers.org/srfi-162/">SRFI 162</a>.</body></html> \ No newline at end of file
diff --git a/srfi-228-test.scm b/srfi-228-test.scm
new file mode 100644
index 0000000..85814bb
--- /dev/null
+++ b/srfi-228-test.scm
@@ -0,0 +1,83 @@
+(cond-expand
+ (chibi
+ (import (chibi test)
+ (scheme base)
+ (srfi 1)
+ (srfi 128)
+ (only (srfi 132) list-sort))))
+
+(define-record-type Person
+ (make-person first-name last-name)
+ person?
+ (first-name person-first-name)
+ (last-name person-last-name))
+
+(define person-name-comparator
+ (make-product-comparator
+ (make-wrapper-comparator person? person-last-name string-ci-comparator)
+ (make-wrapper-comparator person? person-first-name string-ci-comparator)))
+
+(test-group "simple"
+ (test-equal eq?
+ #t
+ (<? person-name-comparator
+ (make-person "John" "Cowan")
+ (make-person "Daphne" "Preston-Kendal")))
+
+ (test-equal eq?
+ #t
+ (>? person-name-comparator
+ (make-person "Tom" "Smith")
+ (make-person "John" "Smith"))))
+
+(define-record-type Book
+ (make-book author title)
+ book?
+ (author book-author)
+ (title book-title))
+
+(define book-comparator
+ (make-product-comparator
+ (make-wrapper-comparator book? book-author person-name-comparator)
+ (make-wrapper-comparator book? book-title string-ci-comparator)))
+
+(define-record-type CD
+ (make-cd artist title)
+ cd?
+ (artist cd-artist)
+ (title cd-title))
+
+(define cd-comparator
+ (make-product-comparator
+ (make-wrapper-comparator cd? cd-artist person-name-comparator)
+ (make-wrapper-comparator cd? cd-title string-ci-comparator)))
+
+(define item-comparator
+ (make-sum-comparator book-comparator cd-comparator))
+
+(test-group "nested"
+ (let* ((beatles (make-person "The" "Beatles"))
+ (abbey-road (make-cd beatles "Abbey Road"))
+ (deutsche-grammatik
+ (make-book (make-person "Jacob" "Grimm") "Deutsche Grammatik"))
+ (sonnets (make-book (make-person "William" "Shakespeare") "Sonnets"))
+ (mnd (make-book (make-person "William" "Shakespeare")
+ "A Midsummer Night’s Dream"))
+ (bob (make-cd (make-person "Bob" "Dylan") "Blonde on Blonde"))
+ (revolver (make-cd (make-person "The" "Beatles") "Revolver")))
+ (test-equal
+ equal?
+ (list-sort
+ (lambda (a b) (<? item-comparator a b))
+ (list abbey-road
+ deutsche-grammatik
+ sonnets
+ mnd
+ bob
+ revolver))
+ (list deutsche-grammatik
+ mnd
+ sonnets
+ abbey-road
+ revolver
+ bob)))) \ No newline at end of file
diff --git a/srfi-228.html b/srfi-228.html
index ba54b5a..76aee7f 100644
--- a/srfi-228.html
+++ b/srfi-228.html
@@ -25,13 +25,14 @@
<li>60-day deadline: 2021-10-30</li>
<li>Draft #1 published: 2021-08-31</li>
<li>Draft #2 published: 2022-02-26</li>
+ <li>Draft #3 published: 2022-11-14</li>
</ul>
<h2 id="abstract">Abstract</h2>
-<p>Further procedures for defining <a href="https://srfi.schemers.org/srfi-128/srfi-128.html">SRFI 128</a> comparators.
+<p>Further procedures for defining <a href="https://srfi.schemers.org/srfi-128/">SRFI 128</a> comparators.
-<p>Best enjoyed in combination with <a href="https://srfi.schemers.org/srfi-162/srfi-162.html">SRFI 162</a>.
+<p>Best enjoyed in combination with <a href="https://srfi.schemers.org/srfi-162/">SRFI 162</a>.
<h2 id="issues">Issues</h2>
@@ -189,7 +190,7 @@
<h2 id=future-work>Future Work</h2>
-<p>The author hopes that a future SRFI will add a procedure for creating comparators yielding lexicographical order over any sequence type by delegating to a common iteration protocol. An idea to do this using <code>fold</code> procedures foundered on two grounds: the first and more intrinsic one is that <code>fold</code> called on two sequences, one of which is a prefix of the other, cannot determine which of the two is longer, and a sort using <code>fold</code>-based iteration would incorrectly consider them equal; the second is that there is currently an inconsistency among Scheme libraries in what order the <var>kons</var> procedure argument to <code>fold</code> receives the accumulator and the next values in the sequence (compare <a href="https://srfi.schemers.org/srfi-1/srfi-1.html#fold">SRFI 1 <code>fold</code></a> with <a href="https://srfi.schemers.org/srfi-133/srfi-133.html#vector-fold">SRFI 133 <code>vector-fold</code></a>). <a href="https://srfi.schemers.org/srfi-158/srfi-158.html">SRFI 158</a> generators were rejected on the ground that their sequences cannot contain any arbitrary Scheme datum.
+<p>The author hopes that a future SRFI will add a procedure for creating comparators yielding lexicographical order over any sequence type by delegating to a common iteration protocol. An idea to do this using <code>fold</code> procedures foundered on two grounds: the first and more intrinsic one is that <code>fold</code> called on two sequences, one of which is a prefix of the other, cannot determine which of the two is longer, and a sort using <code>fold</code>-based iteration would incorrectly consider them equal; the second is that there is currently an inconsistency among Scheme libraries in what order the <var>kons</var> procedure argument to <code>fold</code> receives the accumulator and the next values in the sequence (compare <a href="https://srfi.schemers.org/srfi-1/srfi-1.html#fold">SRFI 1 <code>fold</code></a> with <a href="https://srfi.schemers.org/srfi-133/srfi-133.html#vector-fold">SRFI 133 <code>vector-fold</code></a>). <a href="https://srfi.schemers.org/srfi-158/">SRFI 158</a> generators were rejected on the ground that their sequences cannot contain any arbitrary Scheme datum.
<p>Earlier drafts of this SRFI contained a procedure to convert a SRFI 128 comparator into a set of Scheme comparison procedures. This was dropped because a satisfactory interface, with sufficient efficiency and usability, could not be found. Thanks are due nonetheless to John Cowan and Marc Nieper-Wißkirchen for their suggestions to resolve this issue. Likewise, it is hoped that a future SRFI will respond to this need.
diff --git a/srfi/228.sld b/srfi/228.sld
index b3cca89..834f1ce 100644
--- a/srfi/228.sld
+++ b/srfi/228.sld
@@ -1,10 +1,9 @@
(define-library (srfi 228)
(import (scheme base)
- (srfi 1)
+ (srfi 1)
(srfi 128)
- (srfi 151))
+ (srfi 151))
(export make-wrapper-comparator
make-product-comparator
make-sum-comparator)
-
- (include "composing-comparators.scm"))
+ (include "srfi-228.scm"))
diff --git a/srfi/composing-comparators.scm b/srfi/srfi-228.scm
index 3a93ae4..caca339 100644
--- a/srfi/composing-comparators.scm
+++ b/srfi/srfi-228.scm
@@ -84,4 +84,7 @@
(let ((cmp (%sum-comparator-for comparators x x)))
((comparator-hash-function (car cmp)) x)))
#f)))
+<<<<<<<< HEAD:srfi/composing-comparators.scm
+========
+>>>>>>>> 58c55b3dfe6ebdfd8770cd69ac08acda24dc4f50:srfi/srfi-228.scm