Le vendredi 11 août 2023 à 18:50 -0400, Walter Lewis via General Guile related discussions a écrit : > Sorry I typed that code offhand and it had some mistakes; should be: > > ``` > (use-modules (srfi srfi-9) (system foreign)) > > (define-syntax define-ffi-wrapper >    (syntax-rules () >      ((_ size >          name wrap unwrap predicate >          to-pointer from-pointer) >       (begin >         (define-record-type name >           (wrap bv pointer) >           predicate >           (bv unwrap) >           (pointer pointer-ref pointer-set!)) >         (define (to-pointer x) >           (or (pointer-ref x) >               (let ((pointer (bytevector->pointer x))) >                 (pointer-set! x pointer) >                 pointer))) >         (define (from-pointer pointer) >           (wrap (pointer->bytevector pointer size) >                 pointer)))))) > ``` You could just turn that into a syntax-case macro, use gensym to generate the names, and insert them using with-syntax or quasisyntax. For example (untested): ``` (use-modules (srfi srfi-9) (system foreign)) (define-syntax define-ffi-wrapper (lambda (sintax) (syntax-case sintax () ((_ size name wrap unwrap predicate to-pointer from-pointer) (with-syntax ((pointer-ref (datum->syntax sintax (gensym "pointer-ref"))) (pointer-set! (datum->syntax sintax (gensym "pointer-set!")))) #'(begin (define-record-type name (wrap bv pointer) predicate (bv unwrap) (pointer pointer-ref pointer-set!)) (define (to-pointer x) (or (pointer-ref x) (let ((pointer (bytevector->pointer x))) (pointer-set! x pointer) pointer))) (define (from-pointer pointer) (wrap (pointer->bytevector pointer size) pointer)))))))) ```