Created
March 24, 2012 20:48
-
-
Save samth/2187635 to your computer and use it in GitHub Desktop.
Higher-order functions in C and Racket via the FFI
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 | |
(require ffi/unsafe srfi/67) | |
(define-fun-syntax _unptr | |
(syntax-rules () [(_ t) (type: _pointer pre: (x => (ptr-ref x t)))])) | |
(define qsort | |
(get-ffi-obj 'qsort #f | |
(_fun (l : (_list io _int len)) | |
(len : _int = (length l)) | |
(size : _int = (ctype-sizeof _int)) | |
(compare : (_fun (_unptr _int) (_unptr _int) -> _int)) | |
-> _void -> l))) | |
(qsort | |
'(7 1 2 3 5 6 4 8 0 9) | |
number-compare) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment