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

dequeue removes the wrong list item #188

Open
boykobb opened this issue Sep 28, 2024 · 1 comment
Open

dequeue removes the wrong list item #188

boykobb opened this issue Sep 28, 2024 · 1 comment

Comments

@boykobb
Copy link

boykobb commented Sep 28, 2024

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
Copy link
Collaborator

dmalec commented Sep 28, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants