#lang racket (require ffi/unsafe ffi/unsafe/define) ;; helper to define racket symbols to refer to C symbols (define-ffi-definer my-define (ffi-lib "libmyprint")) ;; typedef. this corresponds to the argument type of my_print (define _my-callback (_cprocedure (list _string) _string)) (my-define my_print (_fun _my-callback -> _string)) ;; racket function which will be passed to c code as a callback ;; returns a string of the first character of its input concatenated ;; four times (define (four-times-the-first str) (make-string 4 (string-ref str 0))) ;; call the C function with our callback ;; output should be "CCCC" (my_print four-times-the-first)