dequeue removes the wrong list item
Opened this issue · 1 comments
boykobb commented
dequeue happens to remove and output the first item of a list (thus being identical to pop), while it should remove and return the last item.
dmalec commented
This is the behavior I am seeing for QUEUE
/ DEQUEUE
:
? MAKE "my.queue (LIST )
? PRINT my.queue
? QUEUE "my.queue "foo
? PRINT my.queue
foo
? QUEUE "my.queue "bar
? PRINT my.queue
foo bar
? QUEUE "my.queue "baz
? PRINT my.queue
foo bar baz
? PRINT DEQUEUE "my.queue
foo
Whereas this is the behavior I'm seeing for PUSH
/ POP
:
? MAKE "my.stack (LIST )
? PRINT my.stack
? PUSH "my.stack "foo
? PRINT my.stack
foo
? PUSH "my.stack "bar
? PRINT my.stack
bar foo
? PUSH "my.stack "baz
? PRINT my.stack
baz bar foo
? PRINT POP "my.stack
baz
So, DEQUEUE
and POP
are both returning the first item in the list; but, if you constructed the list using their counterparts QUEUE
and PUSH
, I believe the code works as expected.
Is there a particular problem you're trying to tackle where it's not so much about the behavior of DEQUEUE
and POP
as it is that you'd like to get the last item from a list? Or are you seeing different behavior than what I'm seeing?