News for hackers. Stuff that matters.
Re:Nim 1.2 by iimblack on Friday April 03, 2020 @01:48PM (#22772110)
Dup is very interesting to me. Does that mean that in Nim all functions will be impure by default, and that it's considered idiomatic to modify the input? I guess it's nice that they're trying to make behavior consistent. It just seems like the opposite of the recent directions I've seen other languages take.
Re:Nim 1.2 by jrhurst on Friday April 03, 2020 @02:03PM (#22772277)
I haven't played with nim for a few months, but only parameters with var will get mutated. I suspect you want to use someone else's cursed function and don't want to poison your blessed code
Re:Nim 1.2 by iimblack on Friday April 03, 2020 @04:10PM (#22773479)
I see. I know nothing about Nim but I do see in their example they used var when declaring the function. This way seems like it's hidden to the consumer of the function but hopefully editor tooling helps with this.
Re:Nim 1.2 by juki on Friday April 03, 2020 @04:29PM (#22773649)
You have to declare the variable as `var` as well, eg.

    var arr1 = [4, 2, 3, 6]
    sort arr1

    # Doesn't work
    let arr2 = [4, 2, 3, 6]
    sort arr2
You'll get a warning about the latter from the compiler (and nimsuggest for editors).
Re:Nim 1.2 by treeform on Friday April 03, 2020 @02:38PM (#22772655)
Mutating in place is often times faster and is more straightforward.

I do feel Nim embraces mutation more than other recent languages.

Re:Nim 1.2 by eindiran on Friday April 03, 2020 @03:28PM (#22773130)
Yeah, the 'discard' keyword is a pretty cool way to note that you're using a procedure only for its side effects.
Re:Nim 1.2 by iimblack on Friday April 03, 2020 @04:12PM (#22773493)
I'm not arguing either way, just noting that it's counter to what I've seen recently in other languages.