Skip to content

Instantly share code, notes, and snippets.

@logc
Created April 10, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logc/3c5801fa367e82884de4593b4036bb32 to your computer and use it in GitHub Desktop.
Save logc/3c5801fa367e82884de4593b4036bb32 to your computer and use it in GitHub Desktop.
How to call Nim from Racket
proc fib(a: cint): cint {.exportc, dynlib.} =
if a <= 2:
result = 1
else:
result = fib(a - 1) + fib(a - 2)
#lang racket/base
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-nim (ffi-lib "libfib"))
(define-nim fib (_fun _int -> _int))
(fib 23) ;; => 28657
nim compile --app:lib -d:release fib.nim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment