Comment by simonw

1 day ago

For anyone wondering, the article clarifies that "A NIF is a function that is implemented in C instead of Erlang".

I had a bunch of fun getting ChatGPT Code Interpreter to write (and compile and test) C extensions for SQLite last year: https://simonwillison.net/2024/Mar/23/building-c-extensions-...

Not only C. Can be done in any compiled language (C, Rust, Zig, etc). Not sure if can be done with GC language.

  • BEAM loads a shared object, that opens the door to anything.

    If you want to use a GC language for NIFs, you'd need to hook up your runtime somehow.

    IMHO, it makes more sense to lean into the BEAM and use its resource management... my NIFs have all been pretty straight forward to write. All the boiler plate is what it is, and figuring out how to cooperate with the scheuduler for long running code or i/o can be a bit tricky, but if you can do a lot in a BEAM language, the native code ends up being like

    Check the arguments, do the thing, return the results.