Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Cool


Actually, Pascal has slices

They are just so obscure, I forgot about them and no one uses them. No users, no problems

They are not part of the normal type system. You cannot declare a variable of a type slice. Nor a field. But when a parameter of a function is an (open) array, you can call the function with a slice of an existing array

That avoids most problems

The backing array exists when the function is called, and the function cannot store the slice, so the slice cannot outlive the array. It is like the function borrows the array. Only problem is if the function gets another reference to the array, through a global variable or something, and resizes it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: