Skip to content

Commit

Permalink
Fix push-last (dylan-lang#1625)
Browse files Browse the repository at this point in the history
This fixes a mismatch between the DRM specification of push-last and the
Open Dylan implementation.
  • Loading branch information
housel authored Aug 2, 2024
2 parents 69c27e4 + 98f6406 commit 544b540
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
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

0 comments on commit 544b540

Please sign in to comment.