From 6a08c86ddeca9612511f425848e6e7eb50187d9d Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Tue, 30 Jul 2024 21:42:11 -0700 Subject: [PATCH 1/2] dylan: Fix return value of push-last According to the DRM, the push-last function is supposed to return the new value added to a deque rather than the deque. * sources/dylan/deque.dylan (trusted-push-last): Change to return the new element. (push-last): Change return signature to reflect returning the new element. * sources/dylan/tests/collections.dylan (test test--functions): New test (inspired by cmu-test-suite) for testing -specific functions and methods. (suite dylan-collections-test-suite): Add test--functions. --- sources/dylan/deque.dylan | 8 ++++---- sources/dylan/tests/collections.dylan | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/dylan/deque.dylan b/sources/dylan/deque.dylan index 808f08c856..ce42c3bf97 100644 --- a/sources/dylan/deque.dylan +++ b/sources/dylan/deque.dylan @@ -517,7 +517,7 @@ end method pop; // define sealed inline method trusted-push-last - (deque :: , new-element) => (result :: ) + (deque :: , new-element) => (new-element) let rep = deque.representation; let rep-last-index = rep.last-index; while (rep-last-index = (rep.size - 1)) @@ -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 :: , new-element) => (result :: ) + (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; diff --git a/sources/dylan/tests/collections.dylan b/sources/dylan/tests/collections.dylan index 50d764b4b8..8720fea374 100644 --- a/sources/dylan/tests/collections.dylan +++ b/sources/dylan/tests/collections.dylan @@ -62,6 +62,22 @@ define test test- () test-collection-class(, instantiable?: #t); end; +define test test--functions () + let d = make-test-instance(); + 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 argument", d == add!(d, 1)); + check-equal("add! added new element to front", 1, pop(d)); + check-true("remove! returns argument", d == remove!(d, 9)); + check-equal("remove! removed final element", 8, pop-last(d)); +end; + define test test- () test-collection-class(, instantiable?: #t); end; @@ -108,6 +124,7 @@ define suite dylan-collections-test-suite () test test-; test test-; test test-; + test test--functions; test test-; test test-; test test-; From 98f64061f7328ed23aca060aa15619bae0bdbd52 Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Tue, 30 Jul 2024 22:17:32 -0700 Subject: [PATCH 2/2] release-notes: Add entry for push-last fix --- documentation/source/release-notes/2024.2.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentation/source/release-notes/2024.2.rst b/documentation/source/release-notes/2024.2.rst index 9f43db4161..c6043de73e 100644 --- a/documentation/source/release-notes/2024.2.rst +++ b/documentation/source/release-notes/2024.2.rst @@ -63,6 +63,12 @@ Tools Library Updates =============== +Dylan +----- + +* The return value of :drm:`push-last` on :drm:`` now matches + that specified in the Dylan Reference Manual. + IO ----