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

Problem with Cloning #32

Open
DavePearce opened this issue Jul 19, 2019 · 0 comments
Open

Problem with Cloning #32

DavePearce opened this issue Jul 19, 2019 · 0 comments

Comments

@DavePearce
Copy link
Member

There is some kind of problem related to cloning. The following from Template_Valid_29 illustrates:

public type Vector<T> is { T[] items, int length } where length <= |items|

function add<T>(Vector<T> vec, T item) -> Vector<T>:
    //
    if vec.length == |vec.items|:
        // vec is full so must resize
        int nlen = (vec.length*2)+1
        // double size of internal array
        T[] nitems = [item; nlen]
        int i = 0
        // copy items
        while i < vec.length:
           nitems[i] = vec.items[i]
           i = i + 1
        //
        vec.items = nitems
    else:
        vec.items[vec.length] = item
    //
    vec.length = vec.length + 1        
    //
    return vec

As far as I can tell, the generated JavaScript seems to be correct. However, subsequent calls of this result in interference between Vectors which should be disjoint.

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

1 participant