News for hackers. Stuff that matters.
Re:Nimrod by Example by perturbation on Thursday July 17, 2014 @01:17PM (#8048837)
Anyone 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.

Re:Nimrod by Example by def- on Thursday July 17, 2014 @01:22PM (#8048870)
For general C/Nimrod interop see these Rosetta Code tasks:

http://rosettacode.org/wiki/Call_a_foreign-language_function...

http://rosettacode.org/wiki/Call_a_function_in_a_shared_libr...

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

When something throws an error I comment it out and try to see if I can fix it up by hand.

Re:Nimrod by Example by perturbation on Monday July 21, 2014 @09:26PM (#8067025)
To 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

Re:Nimrod by Example by ilaksh on Friday July 18, 2014 @01:13AM (#8051772)
I never tried the c2nim thing but just used a few compiler directives I think to call C code. It was incredibly easy.