Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:52:31+00:00 2026-05-15T07:52:31+00:00

This is mostly a follow-up to this question . I decided to just keep

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:52:32+00:00Added an answer on May 15, 2026 at 7:52 am

    I’ve answered most of this question in the other one (I didn’t see this one). It’s fine to use a function that pulls out the bindings like this, but one possible problem here is that since you generate the binding only when the resulting function is called, this binding is re-created on each and every call. An easy way to solve this quickly is using promises, something like this:

    (require scheme/promise)
    (define (get-cpyfunc name type)
      (define the-function
        (delay (if libpython
                 (get-ffi-obj name libpython type)
                 (error "Call init before using any Python C functions"))))
      (lambda args (apply (force the-function) args)))
    

    But this is essentially almost the same as the code I posted in your previous question.

    More random notes:

    • get-ffi-obj will accept a symbol as the name to bind to — this is intentional, to make such macros (as in the last question) easy.

    • Using (symbol->string 'name) in a macro is fine. As I noted above in my comment reply to Nathan’s comment, this means that it gets called at runtime, but mzscheme should be able to optimize that anyway, so there’s no need to try and write some sophisticated macro that does the job at compile time.

    • Look inside the PLT directory — you will find a collection called ffi. This is a collection of examples of bindings with various styles. Macros that create the bindings are very common in these examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is mostly a theoretical question I'm just very curious about. (I'm not trying
As a lot of people pointed out in this question , Lisp is mostly
I think this mostly applies to web applications, since you often see things like
this is the scenario: multiple web systems (mostly lampp/wampp) exist, most of them with
I've managed to mostly ignore all this multi-byte character stuff, but now I need
How would I go about this? I have a mostly static site, which is
Not quite sure how to troubleshoot this. I'm maintaining an ASP site, its mostly
This is starting to vex me. I recently decided to clear out my FTP,
This is a bit of a long shot, but if anyone can figure it
This is kinda oddball, but I was poking around with the GNU assembler today

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.