Skip to content

Commit

Permalink
Update procedures memv and assv 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 Sep 19, 2023
1 parent b03d47a commit 32e6ecb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Subset of R7RS-small.
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.4.808_amd64.deb
sudo apt install build/meevax_0.4.809_amd64.deb
```

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

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.4.808.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.4.809.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.4.808_amd64.deb`
| `package` | Generate debian package `meevax_0.4.809_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.4.808
0.4.809
24 changes: 8 additions & 16 deletions basis/r4rs-essential.ss
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@
(null? x)))
(null? x))))

(define (member o x . c) ; Chibi-Scheme
(let ((compare (if (pair? c) (car c) equal?)))
(let member ((x x))
(and (pair? x)
(if (compare o (car x)) x
(member (cdr x)))))))

(define (memv o x)
(member o x eqv?))

(define-syntax case ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
Expand All @@ -265,19 +255,21 @@
`(,(rename 'let) ((,(rename 'result) ,(cadr form)))
,(each-clause (cddr form))))))

(define (member x xs . compare) ; Chibi-Scheme
(let ((compare (if (pair? compare) (car compare) equal?)))
(let member ((xs xs))
(and (pair? xs)
(if (compare x (car xs)) xs
(member (cdr xs)))))))

(define (assoc key alist . compare) ; Chibi-Scheme
(let ((compare (if (pair? compare)
(car compare)
equal?)))
(let ((compare (if (pair? compare) (car compare) equal?)))
(let assoc ((alist alist))
(if (null? alist) #f
(if (compare key (caar alist))
(car alist)
(assoc (cdr alist)))))))

(define (assv key alist)
(assoc key alist eqv?))

(define (exact? z)
(define (exact-complex? x)
(and (imaginary? x)
Expand Down
4 changes: 4 additions & 0 deletions include/meevax/kernel/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ inline namespace kernel

auto memq(object const&, object const&) -> object const&;

auto memv(object const&, object const&) -> object const&;

auto assq(object const&, object const&) -> object const&;

auto assv(object const&, object const&) -> object const&;

template <typename F>
auto filter(F test, object const& xs) -> object
{
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,20 @@ inline namespace kernel
return memq(xs[0], xs[1]);
});

library.define<accessor>("memv", [](let const& xs) -> auto const&
{
return memv(xs[0], xs[1]);
});

library.define<accessor>("assq", [](let const& xs) -> auto const&
{
return assq(xs[0], xs[1]);
});

library.define<accessor>("assv", [](let const& xs) -> auto const&
{
return assv(xs[0], xs[1]);
});
});

define<library>("(meevax number)", [](library & library)
Expand Down
38 changes: 38 additions & 0 deletions src/kernel/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ inline namespace kernel
}
}

auto memv(object const& x, object const& xs) -> object const&
{
if (xs.is<pair>())
{
if (eqv(x, car(xs)))
{
return xs;
}
else
{
return memv(x, cdr(xs));
}
}
else
{
return f;
}
}

auto assq(object const& x, object const& xs) -> object const&
{
if (xs.is<pair>())
Expand All @@ -103,6 +122,25 @@ inline namespace kernel
}
}

auto assv(object const& x, object const& xs) -> object const&
{
if (xs.is<pair>())
{
if (eqv(x, caar(xs)))
{
return car(xs);
}
else
{
return assv(x, cdr(xs));
}
}
else
{
return f;
}
}

auto longest_common_tail(let const& a, let const& b) -> object const&
{
if (a.is<null>() or b.is<null>() or eq(a, b))
Expand Down

0 comments on commit 32e6ecb

Please sign in to comment.