269 points · by def- · 11y ago · 84 comments
* 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 (easily) to your favorite C functions and libraries
* Control when and for how long the garbage collector runs
* Type safe sets and arrays of enums; this was cool:
"Internally the set works as an efficient bitvector."
* Unified Call Syntax, so mystr.len() is equivalent to len(mystr)
* Good performance -- not placing too much emphasis on this,
but it's faster than C++ in his benchmark
* Compile to JavaScript 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 createCRCTable(): array[256, CRC32] =
for i in result.indices:
I think I should propose adding indices to the standard library.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)).
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!
Obviously, it doesn't matter whether those features are old or new. What matters is whether the language executes them in a compelling way. But almost every single one of those features has been a core aspect of programming languages which have been around since before most of us were born.
Also, the mods have strongly urged me to write shorter comments, and to write comments less frequently. And they've suggested that more than once. I try to oblige, and this is the result. So technically I can't flesh out my comments without going against their advice.
Of that list of nine features, I'm certain six are extremely old:
* 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 (easily) to your favorite C functions and libraries
* Unified Call Syntax, so mystr.len() is equivalent to len(mystr)
* Good performance -- not placing too much emphasis on this,
but it's faster than C++ in his benchmark
I wouldn't be surprised if GC control and typesafe enums are also extremely old, bringing that up to "8 out of 9 features are old." But it's at least 6 out of 9.https://en.wikipedia.org/wiki/Wikipedia:Articles_for_deletio...
At what point does a language become noteworthy enough for a site that contains full entries for side characters in non-canonical Star Wars novels?
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.")
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!)
Additionally, having compiled executables solves a Python pain point. I love Python, but distributing packaged executables is an ongoing pain point.
I haven't seen a better boat for Python refugees to jump into. It's certainly worth evaluating if moving from a Python2 codebase, rather than porting to 3. It's far enough along that it can start poaching users looking for the best place to jump off from 2.x.
The only thing I'd like to see them somehow do, is add a CPython2.x library compatibility layer. If that could somehow be engineered into Nim before 1.0.. I think I'd declare Python3 to be in serious trouble.
The users WILL come if that's done. Maybe take a look at Nuitka in how to make this possible with the binaries that Nim produces. Or even just include the CPython2 runtime in the compiled binary if a user includes Python(2) code.
Could any Nim advocate demonstrate a simple program that:
less than 50 loc
shows the greatest strength (1 killing selling point is enough)
It would probably be better if you explained what kind of problems you're dealing with in your work: we could then look at Nim features and tell you if there's something that would make your life easier and your work more enjoyable.
sadly the reality is not everybody has the time to appreciate the beauty of Nim unless he/she is convinced Nim identifies a problem largely ignored by others and solves it beautifully. my point is, could you convince me?
On the other hand I can definitely see the appeal of it (some python packages go against the recommendation and sort-of taint the style of other sources).
This so far was the only "weird" comment I could think of.
(I'd worry about ambiguities of the experts exchange / expert sex change type, too, but my guess is that they're extremely rare and usually either harmless or instantly caught by the compiler. Still, the mere possibility makes me twitchy.)
It can be used for good too, for example if you have a bunch of different naming conventions in the libraries you use:
proc some_lib_function(x: int) = echo "hi ", x
proc anotherLibFunction(x: int) = echo "hi ", x
proc crAzY_LIB_WRITERS(x: int) = echo "hi ", x
Then you can still call them consistently: someLibFunction(10)
anotherLibFunction(11)
crazyLibWriters(12)While this seems problematic they added some neat features to avoid problems with `uniqueness` of the name and so on.
One thing I wish at this point is to force the compiler to stop if this pattern is not uniform within a codebase.
Either way, I still find the idea a bit weird. If the language wants to be opinionated about naming, maybe it could simply make _ illegal in an identifier or, to push it one level further, refuse to compile any identifier that is not camelCase.
- You cannot have two underscores in a row
- You cannot have a leading underscore
The libraries aren't really there yet. Their number is growing, but some important ones are still missing: http://nim-lang.org/lib.html
So Nim really needs more active users and contributors.
I've fixed an issue you're experiencing: https://github.com/Araq/Nim/issues/1804 :3
I was going through trying to follow the instructions and hit a couple of issues:
-For "You should then add ~/.nimble/bin to your $PATH" it took me quite a while to figure I had to enter "ln -s ~/.nimble/bin/nimble /usr/local/bin/" in my Mac's terminal to do that. I guess experienced devs know that stuff but beginner here.
-There's a bug in the client.nim and server.js code where the client refers to element "foo" but the server refers to element "item". Changing them both to foo got it to work.
Nim seems kinda cool.
Actually you should add "export PATH=$PATH:$HOME/.nimble/bin/" in ~/.profile, ~/.bashrc, ~/.zshrc or whatever your shell requires.
> -There's a bug in the client.nim and server.js code where the client refers to element "foo" but the server refers to element "item". Changing them both to foo got it to work.
Thanks, fixed.
brew install nim
Done and done.[1]: http://brew.sh
export PATH = $PATH:~/.nimble/bin
instead of creating a symbolic link to /usr/local/bin. That way if you put a new binary in ~/.nimble/bin, i.e. if you have ~/.nimble/bin/foonim, it will work without you having to do ln -s ~/.nimble/bin/foonim /usr/local/bin/Add a line to your ~/.profile
#add Nim-lang to path
export PATH=/Users/user/nim/nim-0.10.2/bin:$PATH
In the same terminal window, run 'source ~/.profile' to run the file and update the path. Creating a symbolic link like you did is fine as well.
The result is that C++ now just barely outperforms Nim: 1074ms for C++ vs 1165ms for Nim.
Worth pointing out is that modern C++ does this too. Just add a constexpr, no metaprogramming necessary. Modern C++ really does feel like a new language.
Adding my own optimizations to the compiler sound useful enough. I might see if I can implement this in the language I'm making.
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 totalCould someone give a brief comparison between Clojure and Nim? Let's suppose that we implement Clojure in Nim is this a crazy idea?, What about implementing Shen in Nim?. Many people complain because sbcl is not easy to use with C++ libraries, could an implementation in Nim amilliorate those problems?. Many more questions arise but those mentioned are enough.
$ nim i
>>> for i in 0..10:
... echo "Hello World"[0..i]
...
H
He
Hel
Hell
Hello
Hello
Hello W
Hello Wo
Hello Wor
Hello Worl
Hello World
To use up/down keys, build the Nim compiler with "./koch boot -d:release -d:useGnuReadline" or run "rlwrap nim i" instead.Edit: It's even buggier than I remembered, best avoid it and use "nim -r c file" instead.
[1] https://github.com/pixie-lang/pixie
It'd be possible to implement a Clojure in Nim, you'd just have to port the datastructures and enough primitives to bootstrap the language core (see core.clj, Clojurescript's core.clj, Pixie's stdlib.pxi).
template mysum{a = @[]}(a: seq[int]): int = 0
template mysum{a}(a: seq[int]): int =
while a.low <= a.high:
a[a.low] + mysum(a[a.low + 1 .. a.high])
var x: seq[int] = @[1, 2, 3]
echo mysum(x)