Skip to content

Commit

Permalink
Update character case-insensitive comparison procedures to built-in
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Oct 3, 2023
1 parent 5609bc4 commit 833452e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.19_amd64.deb
sudo apt install build/meevax_0.5.20_amd64.deb
```

or
Expand Down Expand Up @@ -131,9 +131,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.19.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.20.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.19_amd64.deb`
| `package` | Generate debian package `meevax_0.5.20_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.19
0.5.20
32 changes: 1 addition & 31 deletions basis/r4rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@

(define-library (scheme r4rs)
(import (only (meevax boolean) boolean? not)
(only (meevax character)
char?
char=? char<? char>? char<=? char>=?
char-alphabetic? char-numeric? char-whitespace? char-upper-case? char-lower-case?
char->integer integer->char
char-upcase char-downcase
)
(only (meevax character) char? char=? char<? char>? char<=? char>=? char-ci=? char-ci<? char-ci>? char-ci<=? char-ci>=? char-alphabetic? char-numeric? char-whitespace? char-upper-case? char-lower-case? char->integer integer->char char-upcase char-downcase)
(only (meevax core) begin define define-syntax if lambda letrec quote set!)
(only (meevax comparator) eq? eqv? equal?)
(only (meevax complex) make-rectangular make-polar real-part imag-part magnitude angle)
Expand Down Expand Up @@ -342,30 +336,6 @@
(simplest-rational (- x e)
(+ x e)))

(define (char-ci-compare x xs compare) ; Chibi-Scheme
(let rec ((compare compare)
(lhs (char->integer (char-downcase x)))
(xs xs))
(if (null? xs) #t
(let ((rhs (char->integer (char-downcase (car xs)))))
(and (compare lhs rhs)
(rec compare rhs (cdr xs)))))))

(define (char-ci=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs =))

(define (char-ci<? x . xs) ; Chibi-Scheme
(char-ci-compare x xs <))

(define (char-ci>? x . xs) ; Chibi-Scheme
(char-ci-compare x xs >))

(define (char-ci<=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs <=))

(define (char-ci>=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs >=))

(define (string . xs) ; Chibi-Scheme
(list->string xs))

Expand Down
50 changes: 50 additions & 0 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,56 @@ inline namespace kernel
return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-ci=?", [](let const& xs)
{
auto compare = [](let const& a, let const& b)
{
return not (a.as<character>().downcase() == b.as<character>().downcase());
};

return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-ci<?", [](let const& xs)
{
auto compare = [](let const& a, let const& b)
{
return not (a.as<character>().downcase() < b.as<character>().downcase());
};

return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-ci>?", [](let const& xs)
{
auto compare = [](let const& a, let const& b)
{
return not (a.as<character>().downcase() > b.as<character>().downcase());
};

return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-ci<=?", [](let const& xs)
{
auto compare = [](let const& a, let const& b)
{
return not (a.as<character>().downcase() <= b.as<character>().downcase());
};

return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-ci>=?", [](let const& xs)
{
auto compare = [](let const& a, let const& b)
{
return not (a.as<character>().downcase() >= b.as<character>().downcase());
};

return std::adjacent_find(xs.begin(), xs.end(), compare) == xs.end();
});

library.define<predicate>("char-alphabetic?", [](let const& xs)
{
return xs[0].as<character>().property().is_letter();
Expand Down

0 comments on commit 833452e

Please sign in to comment.