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

feat(stdlib): Add mutable doubly-linked list #1845

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alex-snezhko
Copy link
Member

Closes #1815

Wherever I thought it made sense, I made the list functions mutate the given list rather than producing a new list e.g. append

Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation looks really solid. a few little documentaiton issues i noticed.

stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
stdlib/list.gr Outdated Show resolved Hide resolved
Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good To Me.

stdlib/list.gr Outdated Show resolved Hide resolved
Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! People can start to teach Computer Science using Grain now.

This would make a great example of some idiomatic Grain!

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good here, but I have some nits with the high-level design (maybe I missed a conversation):

  1. I think this module should be called Deque, not Mutable. For one, it's not just a mutable singly-linked list, which is what I would expect List.Mutable to be. Second, most languages (e.g. Java and Python) call these structures Deques.
  2. With that change, I think it makes sense to pull this module out of list.gr and put it in its own file.

@alex-snezhko
Copy link
Member Author

@peblair True, but I think an argument in favor of keeping it as a member of the List module is that the interface for this type extends beyond the typical scope of a deque as an abstract data type, notably adding/removing/querying from only the beginning or end of the structure. There are indeed some languages like Python whose collections.deque has more capabilities than just these, but in my view that betrays the purpose of a deque.

I also think in this same way you can draw a parallel between Grain's List and Stack, where the only ways you can "modify" a List (adding to and removing from the front) capture the behavior of a stack, but the other functions made available to the List module like map, etc make it philosophically more general-purpose even though on its face a List is just a stack.

What do you think?

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

Successfully merging this pull request may close these issues.

Add doubly linked list.
4 participants