Lifetimes and References: Follow Up
In my last post, I mentioned some issues with lifetimes and references. I mentioned some possible solutions, but I just had a breakthrough after putting a couple things together. First of all, I decided on something I kind of teased at earlier, which was making regular references work more like C++ references. This means that you can pass pretty much anything to a function with a regular reference in its signature: func addTwo (x: int &) { return x + 2 // implicit dereference } // now you can pass anything to addTwo, as long as it's an integer: let num = 1 // on the stack print (addTwo(num)) // prints 3 let r1 = &num // reference print (addTwo(r1)) // prints 3 let r2 = new int ( 2 ) // smart reference to thing int on the heap print (addTwo(r2)) let r3: const shared int = new int ( 3 ) // experimental syntax for immutable shared reference print (addTwo(r3)) let r4 = new const unique int ( 4 ) // unique smart reference print (addTwo(r4...