From a7fabc471358abc9487df35dfabd669eb63692ff Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Wed, 25 Dec 2024 02:46:44 +0900 Subject: [PATCH] Cleanup member function `syntactic_environment::identify` Signed-off-by: yamacir-kit --- README.md | 4 +-- VERSION | 2 +- .../meevax/kernel/syntactic_environment.hpp | 35 +++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a28bbbfa0..28e9f39d9 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,9 @@ Then, select one of the following targets and `make` it according to your purpos | Target | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.309.so` and executable `meevax`. +| `all` | Build shared-library `libmeevax.0.5.310.so` and executable `meevax`. | `install` | Copy files into `/usr/local` directly. -| `package` | Generate debian package `meevax_0.5.309_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.309_amd64.deb`. +| `package` | Generate debian package `meevax_0.5.310_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.310_amd64.deb`. | `test` | Test executable `meevax`. This target requires Valgrind to be installed. | `uninstall` | Remove files copied to `/usr/local` directly by target `install`. diff --git a/VERSION b/VERSION index 828c6602a..51794f488 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.309 +0.5.310 diff --git a/include/meevax/kernel/syntactic_environment.hpp b/include/meevax/kernel/syntactic_environment.hpp index a5cd19793..944a7e86b 100644 --- a/include/meevax/kernel/syntactic_environment.hpp +++ b/include/meevax/kernel/syntactic_environment.hpp @@ -933,37 +933,38 @@ namespace meevax::inline kernel { assert(variable.is_also()); - auto i = 0; - - for (auto outer = bound_variables; outer.is(); ++i, outer = cdr(outer)) + for (auto i = 0; let formals : bound_variables) { - auto j = 0; - - for (auto inner = outer.is() ? car(outer) : unit; not inner.is(); ++j, inner = inner.is() ? cdr(inner) : unit) + for (auto j = 0; not formals.is(); formals = cdr(formals)) { - if (inner.is()) + if (formals.is()) { - if (car(inner).is() and eq(caar(inner), variable)) + if (car(formals).is() and eq(caar(formals), variable)) { - return car(inner); + return car(formals); } - else if (eq(car(inner), variable)) + else if (eq(car(formals), variable)) { return make(make(i), make(j)); } } - else if (inner.is_also() and eq(inner, variable)) + else if (formals.is_also() and eq(formals, variable)) { return make(make(i), make(j)); } + + ++j; } + + ++i; } - if (variable.is()) // Resolve alias + if (variable.is() and + variable.as().form.template is_also()) // if is an alias { return variable.as() .environment - .template as() + .template as_const() .identify(variable.as().form, unify(car(variable.as().environment), bound_variables)); @@ -977,11 +978,9 @@ namespace meevax::inline kernel inline auto identify(object const& variable, object const& bound_variables) { - if (not variable.is_also()) - { - return f; - } - else if (let const& identity = std::as_const(*this).identify(variable, bound_variables); identity != f) + assert(variable.is_also()); + + if (let const& identity = std::as_const(*this).identify(variable, bound_variables); identity != f) { return identity; }