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

[BUG]: no way to append to a list, returning a new list with the added value #4127

Closed
paultag opened this issue Oct 9, 2024 · 3 comments
Closed
Labels
feature Feature Requests kcl Language and compiler features

Comments

@paultag
Copy link
Collaborator

paultag commented Oct 9, 2024

Describe the bug

I would like to be able to append to a list -- something like:

fn x = (something) => {
    return something.append(1)
}

const y = x([3, 2])

Steps to Reproduce

n/a

Expected Behavior

n/a

Screenshots and Recordings

No response

Desktop OS

Debian

Browser

Chrome

Version

main

Additional Context

No response

@paultag paultag added the bug Something isn't working label Oct 9, 2024
@paultag paultag changed the title [BUG]: [BUG]: no way to append to a list, returning a new list with the added value Oct 9, 2024
@jessfraz jessfraz added the kcl Language and compiler features label Oct 9, 2024
@nrc nrc added feature Feature Requests and removed bug Something isn't working labels Oct 9, 2024
@nrc
Copy link
Contributor

nrc commented Oct 17, 2024

What's your use case for this? I'm curious about the larger task you're doing that requires it

@jtran
Copy link
Collaborator

jtran commented Oct 28, 2024

#4232 implements this by the most straight forward approach of cloning the Vec and pushing to it.

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.

As an alternative, I propose persistent data structures since they fit better with immutability. Clojure makes good use of hash array mapped tries to provide a persistent interface, while mutating internally for better performance.

@jtran
Copy link
Collaborator

jtran commented Nov 7, 2024

Resolved by #4341.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature Requests kcl Language and compiler features
Projects
None yet
Development

No branches or pull requests

4 participants