Created
April 10, 2018 09:27
-
-
Save logc/3c5801fa367e82884de4593b4036bb32 to your computer and use it in GitHub Desktop.
How to call Nim from Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc fib(a: cint): cint {.exportc, dynlib.} = | |
if a <= 2: | |
result = 1 | |
else: | |
result = fib(a - 1) + fib(a - 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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