Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix push-last #1625

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions documentation/source/release-notes/2024.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Tools
Library Updates
===============

Dylan
-----

* The return value of :drm:`push-last` on :drm:`<deque>` now matches
that specified in the Dylan Reference Manual.

IO
----

Expand Down
8 changes: 4 additions & 4 deletions sources/dylan/deque.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ end method pop;
//

define sealed inline method trusted-push-last
(deque :: <object-deque>, new-element) => (result :: <deque>)
(deque :: <object-deque>, new-element) => (new-element)
let rep = deque.representation;
let rep-last-index = rep.last-index;
while (rep-last-index = (rep.size - 1))
Expand All @@ -529,13 +529,13 @@ define sealed inline method trusted-push-last
end while;
rep.last-index := rep-last-index := rep-last-index + 1;
island-deque-element(rep, rep-last-index) := new-element;
deque
new-element
end method trusted-push-last;

define sealed method push-last
(deque :: <object-deque>, new-element) => (result :: <deque>)
(deque :: <object-deque>, new-element) => (new-element)
check-type(new-element, element-type(deque));
trusted-push-last(deque, new-element);
trusted-push-last(deque, new-element)
end method push-last;


Expand Down
17 changes: 17 additions & 0 deletions sources/dylan/tests/collections.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ define test test-<deque> ()
test-collection-class(<deque>, instantiable?: #t);
end;

define test test-<deque>-functions ()
let d = make-test-instance(<deque>);
for (i from 5 to 1 by -1)
check-equal("push returns new value", i, push(d, i));
end for;
for (i from 6 to 10)
check-equal("push-last returns new value", i, push-last(d, i));
end for;
check-equal("first pop is last item inserted at start", 1, pop(d));
check-equal("first pop-last is last item inserted at end", 10, pop-last(d));
check-true("add! returns <deque> argument", d == add!(d, 1));
check-equal("add! added new element to front", 1, pop(d));
check-true("remove! returns <deque> argument", d == remove!(d, 9));
check-equal("remove! removed final element", 8, pop-last(d));
end;

define test test-<list> ()
test-collection-class(<list>, instantiable?: #t);
end;
Expand Down Expand Up @@ -108,6 +124,7 @@ define suite dylan-collections-test-suite ()
test test-<simple-object-vector>;
test test-<stretchy-vector>;
test test-<deque>;
test test-<deque>-functions;
test test-<list>;
test test-<pair>;
test test-<empty-list>;
Expand Down