Skip to content

Problem with Cloning #32

Open
Open

Description

@DavePearce

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions