I am creating an Immutable Linked List class in VBA. It provides ToArray and ToCollection methods, which I have both verified as working. However the Get NewEnum() As IUnknown property is not working and I don't know why.
Public Property Get NewEnum() As IUnknown Attribute NewEnum.VB_UserMemId = -4 Set NewEnum = ToCollection.[_NewEnum] End Property Stepping through the following code with sequence as an SList with the debugger
Public Function Copy(ByVal sequence As Variant) As SList Dim made As New SList Dim element As Variant For Each element In sequence Set made = made.Cons(element) Next Set Copy = made.Reverse End Function shows the For Each element In sequence calling Get NewEnum which builds the collection properly and then returns to Copy and exits the loop after performing no iterations and no errors. My only guess is that NewEnum is an iterator to a variable that is being destroyed when it exits Get NewEnum. Is that what is happening?