Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Add `test` and `tests` directories to `PYTHONPATH` automatically during `basilisp test` CLI invocations (#1069)

### Fixed
* Fix a bug where transient vectors were not callable and did not support `nth` (#1331)

## [v0.5.0]
### Added
* Added support for Python 3.14 (#1282)
Expand Down
2 changes: 2 additions & 0 deletions src/basilisp/lang/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
IAssociative,
IBlockingDeref,
IDeref,
IIndexed,
ILookup,
IMapEntry,
IPersistentCollection,
Expand Down Expand Up @@ -1454,6 +1455,7 @@ def _nth_none(_: None, i: int, notfound=__nth_sentinel) -> None:


@nth.register(Sequence)
@nth.register(IIndexed)
def _nth_sequence(coll: Sequence, i: int, notfound=__nth_sentinel):
try:
return coll[i]
Expand Down
6 changes: 6 additions & 0 deletions src/basilisp/lang/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def __eq__(self, other):
def __len__(self):
return len(self._inner)

def __getitem__(self, item):
return self._inner[item]

def __call__(self, k: int) -> T | None:
return self._inner[k]

def cons_transient(self, *elems: T) -> "TransientVector[T]": # type: ignore[override]
for elem in elems:
self._inner.append(elem)
Expand Down
23 changes: 20 additions & 3 deletions tests/basilisp/core/test_transients.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
[]
[:a :b :c]))

(testing "callable"
(are [v idx res] (= res ((transient v) idx))
[1] 0 1
[:a :b :c] 1 :b)

(are [v idx] (thrown? python/IndexError ((transient v) idx))
[] 0
[] 1
[:a :b :c] 4))

(testing "count"
(let [trx (volatile! (transient [:a :b :c]))]
(is (= 3 (count @trx)))
Expand All @@ -116,13 +126,20 @@

(testing "get"
(are [x y z] (= z (get (transient x) y))
[] 1 nil
[] 1 nil
[:a :b :c] 1 :b)

(is (= :e (get (transient [:a :b :c]) 4 :e))))

(testing "not seqable"
Comment thread
chrisrink10 marked this conversation as resolved.
(is (thrown? python/TypeError (seq (transient []))))))
(testing "nth"
(are [v idx res] (= res (nth (transient v) idx))
[1] 0 1
[:a :b :c] 1 :b)

(are [v idx] (thrown? python/IndexError (nth (transient v) idx))
[] 0
[] 1
[:a :b :c] 4)))

(deftest assoc!-test
(testing "maps"
Expand Down
Loading