Skip to content

Commit 024a84b

Browse files
authored
Return last evaluated from load functions (#984)
Emerged from #979.
1 parent e90bfdc commit 024a84b

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313
* Improved on the nREPL server exception messages by matching that of the REPL user friendly format (#968)
1414
* 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)
15+
* Load functions (`load`, `load-file`, `load-reader`, etc) now return the value of the last form evaluated. (#984)
1516

1617
### Fixed
1718
* Fixed inconsistent behavior with `basilisp.core/with` when the `body` contains more than one form (#981)
1819

1920
### Removed
20-
* Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976)
21+
* Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976)
2122

2223
### Other
2324
* Run PyPy CI checks on Github Actions rather than CircleCI (#971)

src/basilisp/core.lpy

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,12 +4516,13 @@
45164516
(.resolve)
45174517
(python/str))
45184518
ctx (basilisp.lang.compiler.CompilerContext. (or src "<Load Input>"))]
4519-
(doseq [form (seq (basilisp.lang.reader/read reader
4520-
*resolver*
4521-
*data-readers*))]
4522-
(basilisp.lang.compiler/compile-and-exec-form form
4523-
ctx
4524-
*ns*))))
4519+
(last
4520+
(for [form (seq (basilisp.lang.reader/read reader
4521+
*resolver*
4522+
*data-readers*))]
4523+
(basilisp.lang.compiler/compile-and-exec-form form
4524+
ctx
4525+
*ns*)))))
45254526

45264527
(defn load-file
45274528
"Read and evaluate the set of forms contained in the file located at ``path``.
@@ -4581,8 +4582,8 @@
45814582
:lpy:fn:`load-file` (or perhaps :lpy:fn:`load-reader` or :lpy:fn:`load-string`) to
45824583
this function."
45834584
[& paths]
4584-
(doseq [path (seq paths)]
4585-
(load-file (str (resolve-load-path path) ".lpy"))))
4585+
(last (for [path (seq paths)]
4586+
(load-file (str (resolve-load-path path) ".lpy")))))
45864587

45874588
(defn ^:inline load-string
45884589
"Read and evaluate the set of forms contained in the string ``s``\\."

tests/basilisp/test_core_fns.lpy

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,13 +2302,15 @@
23022302

23032303
(deftest load-test
23042304

2305-
(let [load-dir-test "tests/basilisp/corpus"
2306-
load-dir-filepath (str load-dir-test "/core_load_1.lpy")]
2305+
(let [load-dir-test (str "tests/basilisp/corpus")
2306+
load-dir-filepath (str load-dir-test "/core_load_1.lpy")
2307+
load-dir-otherfile (str load-dir-test "/core_load_2.lpy")]
23072308
(try
23082309
(when (bio/exists? load-dir-test)
23092310
(shutil/rmtree load-dir-test))
23102311
(bio/make-parents load-dir-filepath)
2311-
(spit load-dir-filepath "(print :core-load-1)")
2312+
(spit load-dir-filepath "(print :core-load-1) :core-load-1")
2313+
(spit load-dir-otherfile "(print :core-load-2) :core-load-2")
23122314

23132315
(testing "relative load path"
23142316
(let [output (with-out-str (load "corpus/core-load-1"))]
@@ -2322,6 +2324,17 @@
23222324
(testing "non-existent load path"
23232325
(is (thrown? python/FileNotFoundError (load "corpus/core-load-99"))))
23242326

2327+
(testing "load multiple files"
2328+
(let [output (with-out-str (load "corpus/core-load-1"
2329+
"corpus/core-load-2"))]
2330+
(is (= ":core-load-1:core-load-2" output))))
2331+
2332+
(testing "return last form"
2333+
(let [output (load "corpus/core-load-1")]
2334+
(is (= :core-load-1 output)))
2335+
(let [output (load "corpus/core-load-1" "corpus/core-load-2")]
2336+
(is (= :core-load-2 output))))
2337+
23252338
(finally
23262339
(when (bio/exists? load-dir-test)
23272340
(shutil/rmtree load-dir-test))))))

0 commit comments

Comments
 (0)