News for hackers. Stuff that matters.
Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @11:06AM (#27165854)
Can you give an example of noisy syntax? Is it in relation to the type system?

I'm writing Nim every day recently; I haven't experienced it being noisy, but I also don't have extensive or recent experience with Python.

Re:Nim 2.0 thoughts by adenozine on Saturday May 15, 2021 @11:27AM (#27166047)
Sure.

I'm on phone, so hopefully this paste doesn't look awful, but it's right from the website homepage

iterator oddNumbers[Idx, T](a: array[Idx, T]): T = for x in a: if x mod 2 == 1: yield x

The three different sets of brackets, the mixed : and =, it just seems inelegant to me.

I don't really know how I'd improve it, so it's just pointless, ignorant complaining on my part. Pay me little mind.

Re:Nim 2.0 thoughts by xigoi on Saturday May 15, 2021 @11:35AM (#27166134)
The equivalent in Python would be:

  T = TypeVar("T")
  def odd_numbers(a: list[T]) -> Iterator[T]:
      # implementation
I don't really find that less verbose, in terms of brackets and symbols…
Re:Nim 2.0 thoughts by adenozine on Saturday May 15, 2021 @11:57AM (#27166344)
Yeah, I guess you're right.
Re:Nim 2.0 thoughts by memco on Saturday May 15, 2021 @01:55PM (#27167372)
Does Nim have comprehensions? Even if you're striving for equivalent signatures the inner body of the function can be expressed as a comprehension in Python:

  T = TypeVar("T")
  def odd_numbers(a: Iterable[T]) -> Iterator[T]:
    yield from (n for n in a if n % 2 == 1)
Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @02:18PM (#27167568)
Re:Nim 2.0 thoughts by nerdponx on Sunday May 16, 2021 @07:56AM (#27173045)
I think the "full" version is easier to read:

    T = TypeVar("T")
    def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
        for n in nums:
            if n % 2 == 1:
                yield n
Although yet another option is to just return the generator instead of immediately yielding from it:

    T = TypeVar("T")
    def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
        return (n for n in a if n % 2 == 1)
Re:Nim 2.0 thoughts by xigoi on Saturday May 15, 2021 @05:58PM (#27169396)
Unfortunately, Nim doesn't have `yield from`, which would make a comprehension useless here. That's one of the things I'm missing in the language.
Re:Nim 2.0 thoughts by planetis on Sunday May 16, 2021 @04:50AM (#27172260)
That's an obscure/not optimal way to write this code though. I mean why would you use LIST comprehension if you are going to yield each element.
Re:Nim 2.0 thoughts by nerdponx on Sunday May 16, 2021 @07:56AM (#27173050)
It's not list comprehension, it's generator comprehension, which is lazily computed. However it's still an unnecessary layer of iteration, when you could just return the comprehension instead.