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

implemented array push #4232

Closed
wants to merge 1 commit into from
Closed

Conversation

guptaarnav
Copy link
Collaborator

Addressing feature request from #4127, added array std lib function 'push' which takes in an array and an element, and returns a new array with the element appended to the end.

Copy link

qa-wolf bot commented Oct 18, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Oct 18, 2024 11:42pm

@jtran
Copy link
Collaborator

jtran commented Oct 28, 2024

This technically works, but if anyone pushes inside a loop, it's O(n^2). Do we really want to introduce this? Seems like a big foot-gun.

I will propose an alternative in the issue.

@nrc
Copy link
Contributor

nrc commented Oct 28, 2024

I haven't reviewed this but I'd be happy to merge for now on the understanding that we need to review all our array functionality and probably change both the interfaces and implementation. I think re-implementing arrays using some kind of other data structure would be a big job and we shouldn't do that until we have a proper plan

@jtran
Copy link
Collaborator

jtran commented Oct 28, 2024

I don't think it would be that much work at our current stage. Assuming we fix #1130, the only things that interact with arrays are literals, map(), reduce(), and a few of the stdlib functions like extrude() that accept an iterable.

But if you @nrc think this is the way to go, that's fine with me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add another test that pushes to an array and tries to get the new element's index on the original array? Using gen_test_fail!(), we assert that it fails since the original array shouldn't get modified. As far as I know, we don't yet have a way to get the length of an array.

@lf94
Copy link
Contributor

lf94 commented Oct 29, 2024

Succeeded by #4341

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

Successfully merging this pull request may close these issues.

4 participants