--- /dev/null
+
+;; (import-define ...) is a combination of an import clause and a
+;; define clause so as to set up a "raw" import with a call wrapper.
+;;
+;
+; (context 'ALSA)
+; (define-import PCM LIB
+; "snd_pcm_open" "int"
+; "void*" PCM ; "void*" ; snd_pcm_t **pcmp [output]
+; "char*" NAME ; const char *name
+; "int" STREAM ; snd_pcm_stream_t stream
+; "int" MODE ; int mode
+; ))
+
+(define-macro (define-import DATA LIB)
+ ;; Make a raw import
+ (println (history true))
+ (letn ((ARGL (transpose (explode (2 (args)) 2)))
+ (HERE (prefix (last (ARGL 1))))
+ (RAW (context (sym (string (println (term HERE)) ".raw"))))
+ (NAME (sym (args 0)))
+ (ARGS (ARGL 1))
+ (FN (cons (sym (args 0) HERE) (filter (fn (x) (!= DATA x)) ARGS)))
+ (LIB (eval LIB))
+ (IMP (apply import (filter string? (cons LIB (args)))))
+ )
+ (println (list 'FN FN))
+ (if DATA
+ (letex ((FN FN)
+ (CALL (cons IMP ARGS))
+ (DATA DATA))
+ (define FN
+ (let ((DATA (pack "Lu" 0)))
+ (when (>= CALL)
+ ((unpack "Lu" DATA) 0)))))
+ (letex ((FN FN) (CALL (cons IMP ARGS)))
+ (define FN CALL))
+ )))
+(global 'define-import)