How do I write a scheme macro that defines a variable and also gets the name of that variable as a s

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-05-28T15:04:31Z Indexed on 2010/05/28 16:41 UTC
Read the original article Hit count: 235

Filed under:
|

This is mostly a follow-up to this question. I decided to just keep YAGNI in mind and created a global variable (libpython). I set it to #f initially, then set! it when init is called. I added a function that should handle checking if that value has been initialized:

  (define (get-cpyfunc name type)
    (lambda args
      (if libpython
        (apply (get-ffi-obj name libpython type) args)
        (error "Call init before using any Python C functions"))))

So now here's what I want to do. I want to define a macro that will take the following:

(define-cpyfunc Py_Initialize (_fun -> _void))

And convert it into this:

(define Py_Initialize (get-cpyfunc "Py_Initialize" (_fun -> _void)))

I've been reading through the macro documentation to try figuring this out, but I can't seem to figure out a way to make it work. Can anyone help me with this (or at least give me a general idea of what the macro would look like)? Or is there a way to do this without macros?

© Stack Overflow or respective owner

Related posts about macros

Related posts about Scheme