diff --git a/CHANGELOG.md b/CHANGELOG.md index d5dd4c31e..bcf1a087f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * Improved on the nREPL server exception messages by matching that of the REPL user friendly format (#968) * Types created via `deftype` and `reify` may declare supertypes as abstract (taking precedence over true `abc.ABC` types) and specify their member list using `^:abstract-members` metadata (#942) + * Load functions (`load`, `load-file`, `load-reader`, etc) now return the value of the last form evaluated. (#984) ### Fixed * Fixed inconsistent behavior with `basilisp.core/with` when the `body` contains more than one form (#981) ### Removed - * Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976) + * Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976) ### Other * Run PyPy CI checks on Github Actions rather than CircleCI (#971) diff --git a/src/basilisp/core.lpy b/src/basilisp/core.lpy index 0f0a61ad6..9b697e4ef 100644 --- a/src/basilisp/core.lpy +++ b/src/basilisp/core.lpy @@ -4516,12 +4516,13 @@ (.resolve) (python/str)) ctx (basilisp.lang.compiler.CompilerContext. (or src ""))] - (doseq [form (seq (basilisp.lang.reader/read reader - *resolver* - *data-readers*))] - (basilisp.lang.compiler/compile-and-exec-form form - ctx - *ns*)))) + (last + (for [form (seq (basilisp.lang.reader/read reader + *resolver* + *data-readers*))] + (basilisp.lang.compiler/compile-and-exec-form form + ctx + *ns*))))) (defn load-file "Read and evaluate the set of forms contained in the file located at ``path``. @@ -4581,8 +4582,8 @@ :lpy:fn:`load-file` (or perhaps :lpy:fn:`load-reader` or :lpy:fn:`load-string`) to this function." [& paths] - (doseq [path (seq paths)] - (load-file (str (resolve-load-path path) ".lpy")))) + (last (for [path (seq paths)] + (load-file (str (resolve-load-path path) ".lpy"))))) (defn ^:inline load-string "Read and evaluate the set of forms contained in the string ``s``\\." diff --git a/tests/basilisp/test_core_fns.lpy b/tests/basilisp/test_core_fns.lpy index 8c7ecc96d..d70520d33 100644 --- a/tests/basilisp/test_core_fns.lpy +++ b/tests/basilisp/test_core_fns.lpy @@ -2302,13 +2302,15 @@ (deftest load-test - (let [load-dir-test "tests/basilisp/corpus" - load-dir-filepath (str load-dir-test "/core_load_1.lpy")] + (let [load-dir-test (str "tests/basilisp/corpus") + load-dir-filepath (str load-dir-test "/core_load_1.lpy") + load-dir-otherfile (str load-dir-test "/core_load_2.lpy")] (try (when (bio/exists? load-dir-test) (shutil/rmtree load-dir-test)) (bio/make-parents load-dir-filepath) - (spit load-dir-filepath "(print :core-load-1)") + (spit load-dir-filepath "(print :core-load-1) :core-load-1") + (spit load-dir-otherfile "(print :core-load-2) :core-load-2") (testing "relative load path" (let [output (with-out-str (load "corpus/core-load-1"))] @@ -2322,6 +2324,17 @@ (testing "non-existent load path" (is (thrown? python/FileNotFoundError (load "corpus/core-load-99")))) + (testing "load multiple files" + (let [output (with-out-str (load "corpus/core-load-1" + "corpus/core-load-2"))] + (is (= ":core-load-1:core-load-2" output)))) + + (testing "return last form" + (let [output (load "corpus/core-load-1")] + (is (= :core-load-1 output))) + (let [output (load "corpus/core-load-1" "corpus/core-load-2")] + (is (= :core-load-2 output)))) + (finally (when (bio/exists? load-dir-test) (shutil/rmtree load-dir-test))))))