On 07/21/2010 12:51 PM, Evan Hanson wrote: > In an effort to learn scheme, I ported some bindings for a subset of > the OS X CoreMIDI API from a Ruby project of mine to scheme/foreign. > I'm posting them (a) in case anyone wants to use them, but more > because (b) I'm hoping for some feedback. I'm sure there are places > where I could have done things better, more idiomatically, etc. Any > advice is appreciated (but file this one under "non-emergency").
A couple thoughts: 1) Use provide/contract for your library's entry points. Besides making your library safer to use, they act as a basic kind of documentation. Also, using contracts in this program will be a little lesson in name management: ffi/unsafe and racket/contract have different bindings for ->, so you'll need to prefix or rename one of them. E.g., (require (rename-in racket/contract [-> c->])) 2) Consider using tagged pointers instead of just _pointer. For example, you could turn this: (define midi-get-destination (ffi-load "MIDIGetDestination" (_fun _item-count ; returns a -> _pointer))) ; MIDIEndPointRef * into this: (define-cpointer-type _midi-end-point-ref) ... (define midi-get-destination (ffi-load "MIDIGetDestination" (_fun _item-count -> _midi-end-point-ref))) (That is, if I remember how tagged pointers work correctly.) And then by all means put it up on planet.racket-lang.org! Ryan > Also, is this the kind of thing that should be namespaced? In > contrast to other languages where namespacing is used heavily > (sometimes even to a fault), it seems that many scheme libraries are > quite flat. Is this simply left up to the user to manage, or does the > module system take care of this, or is there something else I'm > missing altogether? Forgive the naïveté if this should be clear to > me. _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users