Re:Nim v2.0 Released
by netbioserror on Tuesday August 01, 2023 @10:52AM
(#36956704)
Basically, but it requires no extra syntax. `var some_seq = @[1, 2, 3, 4]` is a stack-managed sequence. That's all there is to it. There's no unwrapping any pointers or boxes or what-not, the type is just `seq[int]`. Put another way, things that have become best practice in C++ are default in Nim with no syntactic noise.
[ Parent
| on HN ]
Re:Nim v2.0 Released
by CyberDildonics on Tuesday August 01, 2023 @11:31AM
(#36957322)
There's no unwrapping any pointers or boxes or what-not
That doesn't happen by default in C++ either.
std::vector<int> some_seq{1, 2, 3, 4, 5, 7};
or even just
std::vector some_seq{1, 2, 3, 4, 5, 7};
nowadays (for a value of nowadays that is 5 years old for GCC and 6 years old for Clang)Indeed there's no question that Nim is basically following C++'s lead on this. Nim iirc always had constructors and destructors. Final piece of the puzzle is move semantics, and I recall a blog post where Araq came up with something very similar.
Re:Nim v2.0 Released
by shirleyquirk on Tuesday August 01, 2023 @03:16PM
(#36961069)
yes, Nim has move semantics, but takes care of you more than c++ does.
for example, if you use an object that was previously moved, you dont get garbage, the compiler turns the first move into a copy (and tells you)
the relevant docs are here: https://nim-lang.org/docs/destructors.html