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

Investigate immutability check #23

Open
MatheusRich opened this issue Jan 8, 2024 · 0 comments
Open

Investigate immutability check #23

MatheusRich opened this issue Jan 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@MatheusRich
Copy link
Collaborator

How about using a ~ prefix to denote mutable variables (and make all vars immutable by default?)?

I experimented with ChatGPT a bit:

fn bubble_sort(~vec) {
    let len = ~vec.len()
    let ~swapped = true
    
    while swapped {
        swapped = false
        for i in 1..len {
            if ~vec[i - 1] > ~vec[i] {
                let temp = ~vec[i - 1]
                ~vec[i - 1] = ~vec[i]
                ~vec[i] = temp
                swapped = true
            }
        }
    }
}

fn main!() {
    let ~unsorted = [4, 2, 7, 1, 9, 5]
    
    println("Unsorted Array: {unsorted}")
    
    let sorted = bubble_sort(unsorted)
    
    println("Sorted Array: {sorted}")
}

main!()
@MatheusRich MatheusRich added the enhancement New feature or request label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant