18 ms·
Nimrod by Example
- eudox 12y agoI'm afraid the memory management scheme might cause the Nimrod ecosystem to end up with too many libraries that require GC, and since the building blocks are already using it, why not use it yourself? Either make it fully manual, or do something like Rust (No small feat). A GC you can switch on and off sounds like a good idea, but programmers don't keep half the promises they make ("It's just an MVP, I'll refactor it to use manual memory later").
- charlieflowers 12y agoStill, there are times when GC is fine for a particular application. In those cases, Nimrod is pretty fantastic, especially given its metaprogramming capabilities.
- def- 12y agoAlso, the GC can be controlled, so you can set exactly when it is allowed to run, something like this for a game: gcDisable() while true: gameLogic() renderFrame() gcStep(us = leftTime) sleep(restTime) http://nimrod-lang.org/gc.html http://nimrod-lang.org/gc.html
- FnuGk 12y agoThen what happens if the GC keeps taking longer than the allowed time? Will it then not keep allocating more and more memory that will never be freed?
- def- 12y agoI guess so. This is only viable if you have enough time for garbage collection.
- camperman 12y agoNimrod's pointers to garbage collected memory are separate from the pointers you can allocate yourself. So you could do manual memory management on the parts that really need it - say for a game in a tight loop - and leave the collector to worry about the smaller and less time-critical stuff. Also the GC is only triggered on a memory allocation. It doesn't run in a background thread or anything like that. So if the GC fails, then the allocation of memory fails (as I understand it) which means your scenario would be caught early.
- Dewie 12y ago> Nimrod's pointers to garbage collected memory are separate from the pointers you can allocate yourself. Does this mean that they use different heaps?
- mcguire 12y agoLikely, yes. (Welcome to real-time programming; if you don't keep track of your time-budget, you're gonna have a bad day.) I haven't looked at Nimrod's GC, but I believe it's indeed incremental; it won't take more time than you give it, but it will leave things uncollected if you don't give it [enough] time.
- sitkack 12y agoin a game, detect gc pressure and schedule some slo mo candy to use as gc cover.
- rbehrends 12y ago> I'm afraid the memory management scheme might cause the Nimrod ecosystem to end up with too many libraries that require GC, and since the building blocks are already using it, why not use it yourself? And what would be the problem with that? The number of application domains where even soft real-time GC is inappropriate is very, very small. And designing freedom from garbage collection into a language (other than the simple option of allowing manual allocation/deallocation) is not cost-free, either, and can weigh down the design, too. You can optimize your language design for having garbage collection or for not having garbage collection, but if you try to do both at once, a language design that specifically favors one or the other will likely beat out the compromise solution for the case it's optimized for. And yes, that means that Nimrod (or any other language) won't be perfect for everything under the sun. Which is fine: there's nothing wrong with having multiple programming languages, each of which is better suited for a different task.
- audunw 12y agoNo, I think Nimrod's approach is absolutely correct. What I hope will happen is that once Nimrod's effects system matures, the compiler will be able to figure out when it can statically free references when they go out of scope, rather than always using the GC. Rusts approach, I think, is in the entirely wrong direction. You should only have one kind of reference, but if you use it correctly the compiler should figure out how to free it. You should then be able to make an assertion that a procedure (possibly "main") does not allocate any GC memory, and have the compiler tell you what part of your code violates this constraint.
- eudox 12y agoI agree in that I don't entirely buy Rust's approach, mostly because of the cognitive overhead that it puts on me, but I don't think it's plausible to think future changes to the compiler (Without the introduction of new constraints on the behaviour of pointers) will give us statically-determined deallocation points. If it were possible, it would have been done five years ago and merged into clang!
- pcwalton 12y agoIt's trivially impossible with unrestricted aliasing. No compiler can statically predict the properties of an unrestricted arbitrary graph about which, in the limit, absolutely nothing is known until runtime.
- TylerE 12y agoSo, because something doesn't work in some theoretical corner cases, it isn't worth bothering with at all?
- pcwalton 12y agoCreating arbitrary graphs in memory is not a "theoretical corner case". It corresponds to, for example, Graphviz reading in a graph from user input. Or, if you want something that could technically be done with manual memory management but might as well be an unrestricted graph for all any reasonable analysis could infer, creating a doubly-linked XML/HTML DOM.
- tdees40 12y agoSighs. I wish Nimrod were more popular. It seems like a better version of D. But there can only be so many languages with a fully functioning ecosystem, and I just doubt Nimrod will ever get there. It seems to be a one-man shop at this point (as this demonstrates): https://github.com/Araq/Nimrod/graphs/contributors https://github.com/Araq/Nimrod/graphs/contributors
- rsaarelm 12y agoThis. I'm on the lookout for expressive, statically typed, native code compiling languages for game development. Currently poking around with Rust, since Go seems to pretty much be settled on not doing the custom expressibility thing. Nimrod looks like something I'd really want to like, the game stuff I do doesn't really need Rust's hardcore garbage collection avoidance, but the ecosystem sparsity just scares me off. Meanwhile, Rust has both reasonably heavy institutional support and an impressive swarm of adventurous game developers with a C++ background working on stuff for it. I'm banking on Rust mostly for the potential ecosystem strength in being the only alternative to C++ for a high level of abstraction don't pay for what you don't use language.
- def- 12y agoThe standard library is pretty nice though: http://nimrod-lang.org/lib.html http://nimrod-lang.org/lib.html I spent a few days solving Rosetta Code tasks and was surprised how easy most were using the existing libraries: http://rosettacode.org/wiki/Category:Nimrod http://rosettacode.org/wiki/Category:Nimrod
- perturbation 12y agoAnyone know the recommended way to do interop with C and Nimrod? I've been doing Project Euler problems in Nimrod, and wanted to use some library functions from GSL for bignum support, but I couldn't really get c2nim to work with the header files. I think that I could use the 'importc'/'dynlib' with the compiled library, but there's not a whole lot of documentation on that in the Nimrod manual, and I ended up just doing that problem in C because it was easier (read: I was lazier) to get working.
- def- 12y agoFor general C/Nimrod interop see these Rosetta Code tasks: http://rosettacode.org/wiki/Call_a_foreign-language_function#Nimrod http://rosettacode.org/wiki/Call_a_foreign-language_function... http://rosettacode.org/wiki/Call_a_function_in_a_shared_library#Nimrod http://rosettacode.org/wiki/Call_a_function_in_a_shared_libr... http://rosettacode.org/wiki/Use_another_language_to_call_a_function#Nimrod http://rosettacode.org/wiki/Use_another_language_to_call_a_f... Making c2nim work with header files can be a bit difficult. The main information is here: http://nimrod-lang.org/c2nim.html http://nimrod-lang.org/c2nim.html When something throws an error I comment it out and try to see if I can fix it up by hand.
- ilaksh 12y agoI never tried the c2nim thing but just used a few compiler directives I think to call C code. It was incredibly easy.
- perturbation 12y agoTo the curious - I got this working (thank you def- for the rosetta code examples!). Point of correction - the library I was actually using for bignum support was GMP, not GSL. (I was getting confused because I used functions from GSL for a different problem). Importing a standard procedure from a C library like GMP actually is pretty easy (use the importc/header pragmas). Here's what tripped me up: * Calling variadic functions from Nimrod (just wrote a wrapper) * Getting to link against gmp (used the passL: "-lgmp" pragma) * Remembering to free what was allocated by C library functions (can't GC what you didn't allocate) - caught with valgrind I'll probably push to my github repo, but can post to a pastebin or something if there's interest in a less cookie-cutter example
- WaxProlix 12y agoIs there a list of "X By Example"-style tutorials around? I learn best from these sorts of things and would love a compendium of sorts.
- ludwigvan 12y agoNot exactly what you're looking for, but http://learnxinyminutes.com/ http://learnxinyminutes.com/ is nice.
- reirob 12y agoThe HN user def- posted a link to the Nimrod section of rosettacode.org: https://news.ycombinator.com/item?id=8048939 https://news.ycombinator.com/item?id=8048939
- gomesnayagam 12y agoI always wanted to go back to C kind of language, let me wait for few more years to pick one Go,Rust,Nimrod...
- aikah 12y agoHow does Nimrod compares to Go regarding concurreny,does it have some libs or some language onstructs ? thanks, I like how the language looks.
- dom96 12y agoNimrod's concurrency support is still evolving but it already implements a builtin thread pool: http://build.nimrod-lang.org/docs/manual.html#spawn http://build.nimrod-lang.org/docs/manual.html#spawn You may also be interested in the C#-like async await as shown in the following news article: http://nimrod-lang.org/news.html#Z2014-04-21-version-0-9-4-released http://nimrod-lang.org/news.html#Z2014-04-21-version-0-9-4-r...