2,741 karma · joined November 25, 2012
https://github.com/3dicc/Urhonimo http://forum.nim-lang.org/t/870
import macros, strutils
macro abcProcs(n: varargs[expr]): stmt =
result = newStmtList()
for c in n.children:
result.add parseStmt("proc $1 = echo \"$1\"" % $c)
abcProcs("A","B","C")
proc execute(order: openarray[int], callbacks: openarray[proc]) =
for i in order:
callbacks[i]()
execute([0,0,1,2,1,2], [A,B,C])https://andreaferretti.github.io/on-rust-and-nim/
https://arthurtw.github.io/2015/01/12/quick-comparison-nim-v...
Edit: The now deleted post was asking about whether Nim code could finally be identified as "Nim" instead of "Nimrod" by Github.
Also there is some overhead every Nim program has. But if you get to bigger programs you'll see that Nim's binary size is just fine, for example a NES emulator is just 136 KB: http://hookrace.net/blog/porting-nes-go-nim/#comparison-of-g...
There are quite some compiler bugs remaining in Nim and the standard library could be improved.
- Predictable performance (lazy evaluation is problematic)
- Easy to achieve high performance
- Easier to read, even for non-specialists
- I'm much more productive in it
- Multi-paradigm: Nim is mostly imperative, but OO and functional can be mixed as well.
http://hookrace.net/blog/conclusion-on-nim/ @if musl:
passL = "-static"
gcc.exe = "/usr/local/musl/bin/musl-gcc"
gcc.linkerexe = "/usr/local/musl/bin/musl-gcc"
@end
Now it compiles like this (SDL2 is still dynamically loaded, +1 MB for that): $ nim -d:release -d:musl c src/nimes
$ ls -lha src/nimes
-rwxr-xr-x 1 def users 219K Mai 1 22:00 src/nimes*I haven't tried GopherJS, but I don't have much Go experience apart from reading it. On a related note, I read that porting the Go version to Android would be difficult and is still far in the future: https://github.com/fogleman/nes/issues/7
- http://hookrace.net/blog/what-is-special-about-nim/
- http://hookrace.net/blog/what-makes-nim-practical/
Summary by benhoyt: https://news.ycombinator.com/item?id=8822918
* 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 JavaScriptI agree that it's a problem with grep, there's a nimgrep tool that you could use instead, but I don't.
The nice part about it is that you can use a consitent naming convention even when using external libraries.
My idea to solve the problems this causes without removing it would be a gofmt like tool as described here: https://github.com/Araq/Nim/wiki/GSoC-2015-Ideas#nimfmt-auto...
If you want the language to handle overflows for you, you can enable runtime overflow checks for your whole code or any specific part of it.
Otherwise, if you opt for no runtime checks and release builds with all optimizations, you indeed go into the same undefined behaviour territority as in C, so you'd have to prevent overflows before they happen.
With ADTs:
data Shape a =
Rectangle
{ x :: Float
, y :: Float
, width :: Float
, height :: Float
}
| Circle
{ x :: Float
, y :: Float
, radius :: Float
}
With Object Variants, note that we don't have to repeat x and y: type
ShapeKind = enum Rectangle, Circle
Shape = object
x, y: float
case kind: ShapeKind
of Rectangle: width, height: float
of Circle: radius: float
The pattern matching in Nim is quite limited. Something like this works: let (x, y) = getCoordinates()
But Nim doesn't have (x,y) = (y,x) for example, instead swap can be used.You could implement your own pattern matching using metaprogramming: http://www.drdobbs.com/open-source/nimrod-a-new-systems-prog...
Araq just announced that Nim has financial backing now: http://forum.nim-lang.org/t/870