Live data from Hacker News

What is special about Nim?

hookrace.net

41–50 of 88 posts

Re: What is special about Nim?

#41
post #39

I copy/pasted the code in the article and compiled each one. I am getting very different ratios compared to the ones you posted: tmp$cc -Wall -O2 test.c -o test && time ./test real 0m1.041s user 0m0.998s sys 0m0.029s nim-0.10.2$./bin/nim --opt:speed c test.nim && time ./test real 0m1.943s user 0m1.894s sys 0m0.036s

Try compiling with -d:release instead of --opt:speed.

Re: What is special about Nim?

#42
post #39

I copy/pasted the code in the article and compiled each one. I am getting very different ratios compared to the ones you posted: tmp$cc -Wall -O2 test.c -o test && time ./test real 0m1.041s user 0m0.998s sys 0m0.029s nim-0.10.2$./bin/nim --opt:speed c test.nim && time ./test real 0m1.943s user 0m1.894s sys 0m0.036s

  $ gcc -O2 -std=c99 -lm -o c c.c
  $ time ./c
  ./c  2.49s user 0.07s system 99% cpu 2.567 total
  $ nim -d:release c nim
  $ time ./nim
  ./nim  2.47s user 0.07s system 99% cpu 2.538 total
Yes, --opt:speed is slower indeed:

  $ nim --opt:speed c nim
  $ time ./nim
  ./nim  3.02s user 0.07s system 99% cpu 3.095 total

Re: What is special about Nim?

#43
post #40

Earlier quoted context omitted.

Honestly, I thing a dozen Nim users should band together and register at Wikipedia to turn the vote the next time someone tries to delete the article. If the deletionists come with formalistic arguments, just synthesize a few articles on sites that fulfill their WP:RELIABLE criteria. There's got to be somebody working for a commercial (read: non-blog) website who doesn't like deletionism and would post a small articl…

Wikipedia is, for some things, severely broken. Your post will be seen by some wikipedians as a violation of some policy or other. (Off the top of my head there's sock puppeting http://en.wikipedia.org/wiki/Wikipedia:Sock_puppetry "Do not ask your friends to create accounts to support you.")

But there is a difference between straight up sockpuppetry, and telling people "If you like Wikipedia but are unsatisfied with the way it currently works, then register and start contributing. If policy discussions or delete votes come up, vote the way you believe you should (namely in this case inclusionist)".

Its a bit like encouraging people to go to elections to raise the voter turnout, to reduce influence of extremist parties. (Not that I'm comparing WP editors with extremists, its just that I believe in both cases there is a silent majority that risks being misrepresented!)

Re: What is special about Nim?

#44
post #34

Earlier quoted context omitted.

As a pythonista one thing that struck me in the code fragments is zeroes and ones appearing everywhere. It looks very easy to have off by one errors. (It is very rare to have off by one errors in Python due to the way counting and ranges work.)

I guess you could use fewer magic numbers if you want, for example instead of: proc createCRCTable(): array[256, CRC32] = for i in 0..255: You can write: proc createCRCTable(): array[256, CRC32] = for i in result.low .. result.high: Or: proc createCRCTable(): array[256, CRC32] = for i, v in result: # index, value Or define your own indices iterator: iterator indices(x) = for i in x.low .. x.high: yield i proc createC…

It isn't magic numbers as such, rather the smattering of sometimes zeroes and sometimes ones. If it was always zero or one it would be a lot less likely to have off by one errors.

Python solves this by always starting from zero, and crucially not including the final number - ie range(0,3) gives 0, 1, 2 (no 3). You can also do negative indexing to count from the end - eg range(0, 3)[-1] gives the last element (2). The right thing happens when you mix the length of things into the arithmetic too - eg range(0, len(item)).

Re: What is special about Nim?

#45
post #41
post #39

I copy/pasted the code in the article and compiled each one. I am getting very different ratios compared to the ones you posted: tmp$cc -Wall -O2 test.c -o test && time ./test real 0m1.041s user 0m0.998s sys 0m0.029s nim-0.10.2$./bin/nim --opt:speed c test.nim && time ./test real 0m1.943s user 0m1.894s sys 0m0.036s

Try compiling with -d:release instead of --opt:speed.

[deleted]

Re: What is special about Nim?

#46
post #39

I copy/pasted the code in the article and compiled each one. I am getting very different ratios compared to the ones you posted: tmp$cc -Wall -O2 test.c -o test && time ./test real 0m1.041s user 0m0.998s sys 0m0.029s nim-0.10.2$./bin/nim --opt:speed c test.nim && time ./test real 0m1.943s user 0m1.894s sys 0m0.036s

Ah -d:release made the results almost identical. Thanks!

Re: What is special about Nim?

#47
post #40

Earlier quoted context omitted.

Wikipedia is, for some things, severely broken. Your post will be seen by some wikipedians as a violation of some policy or other. (Off the top of my head there's sock puppeting http://en.wikipedia.org/wiki/Wikipedia:Sock_puppetry "Do not ask your friends to create accounts to support you.")

But there is a difference between straight up sockpuppetry, and telling people "If you like Wikipedia but are unsatisfied with the way it currently works, then register and start contributing. If policy discussions or delete votes come up, vote the way you believe you should (namely in this case inclusionist)". Its a bit like encouraging people to go to elections to raise the voter turnout, to reduce influence of ext…

I know that and you know that.

There are a considerable number of wikipedia admins who don't see it that way. There are even more young wikipedians who don't yet have adminship who take a hardline on that kind of thing - although to be fair WP has worked hard to reduce that particular malign influence. (Removal of "vandal patrol"; stricter oversight of twinkle and rollback use; etc etc).

Re: What is special about Nim?

#48

Nice article, although I couldn't really understand some of the examples which had template in it.

Agreed. When the manual says you can pattern match with term rewriting macros, I think of Erlang pattern matching. Would something like this be possible?

    template mysum{a = @[]}(a: seq[int]): int = 0
    template mysum{a}(a: seq[int]): int =
      while a.low 

Re: What is special about Nim?

#49
post #3

Great write-up! I expected this to reference a few "normal" language features like static typing, operator overloading, or generics, but instead it was a list of some really neat off-the-beaten-track features: * Run regular code at compile time * Extend the language (AST templates and macros); this can be used to add a form of list comprehensions to the language! * Add your own optimizations to the compiler! * Bind (…

Everything old is new again.

Dont know why you have been downvoted, because this is a kind of "pascal rebirth - the mission".

Of course it borrow some things from Python.. but i dont know why this has to be bad. When i was a kid pascal was a thing.. and my first hello worlds were programmed in it (away from C), then in my teens, Delphi was a thing, relearn to program in it, and it kept me away from Visual Basic (ohh-hay)

Pascal/Delphi was so fun to program with (thanks Hejlsberg!), but somehow the tech world turned into this C syntax dominated world, because of the popularity of the Unix..

And i must say, playing a little bit with Nim, it make me feel that again.. the joy of programming..

And i've always feel Python kind of nasty, i confess, not very easy to read the code.. like a messy code comming from a five year old.. but Nim doesnt have that feel.. it feels like pascal in the old days.. pretty serious but also fun and pragmatic!

Re: What is special about Nim?

#50
post #48

Nice article, although I couldn't really understand some of the examples which had template in it.

Agreed. When the manual says you can pattern match with term rewriting macros, I think of Erlang pattern matching. Would something like this be possible? template mysum{a = @[]}(a: seq[int]): int = 0 template mysum{a}(a: seq[int]): int = while a.low

Term rewriting templates are only supposed to be optimizations, not change the semantics. They happen on the AST, so the pattern matches are on the AST as well. You won't get the actual values of any variables, they aren't even known at compile-time anyway.
Post reply on HN