[gambit-list] Pyffi - Use Python from Racket - Show & Tell - Racket Discussions

Marc-André Bélanger marc-andre.belanger at asciimail.com
Mon Nov 14 10:05:52 EST 2022


Hi Brad,

Here is a copy of a message posted on Hacker News a few weeks ago:

> Pyffi automatically exports Python modules as scheme objects and that's quite practical. We worked on this briefly while building the Gambit interface to CPython (https://github.com/gambit/python), but ran into some quirks with the current Gambit macro and module systems that forced us to postpone. It is definitely something we want!
> Our syntactic interface based on Gambit's infix parser (SIX) is quite ergonomic and allows you to write expressions that look just like Python, within Scheme code (and vice-versa). It's much more natural than directly[1] passing strings to 'eval', although you can certainly do so (the whole low-level API is available). Here's the 'cal' example:
> 
>   > \import calendar
>   > (display (\calendar.month 2022 09))
>      September 2022
>   Mo Tu We Th Fr Sa Su
>             1  2  3  4
>    5  6  7  8  9 10 11
>   12 13 14 15 16 17 18
>   19 20 21 22 23 24 25
>   26 27 28 29 30
> [1]: SIX expressions are compiled to strings and eventually evaluated by CPython's eval.
Pyffi was also the "codename" we used during development :) The two main advantages we have over Pyffi, IMO, are the threading mechanism and syntactic interface (see SW22 paper[1]). While we do allow expressions such as Pyffi's `(run* "x = 1+2")`, we prefer to write it as `\x=1+2` instead (keeps us from passing raw strings around). Also, note that `main.x` in Pyffi will get the `x` global variable (with `sys.modules['__main__'].x` maybe?), whereas in Gambit `main.x` is just a Scheme identifier, as one would expect. Thus to access `x`, we think it's clearer to write `\x`, i.e. we have a clear syntactic distinction between worlds. Similarly with `(object .method arg ...)` which we write as `\object.method(arg, ...)` [2].

As for the ease of installation, it should be almost identical to Pyffi. There is some amount of introspection to be done from within CPython. We have ideas on how to package things more simply, but aren't quite convinced of where to go next yet.

Marc-André Bélanger

[1]: https://andykeep.com/SchemeWorkshop2022/scheme2022-final22.pdf

[2]: Note that Gambit's SIX parser targets multiple languages (JS and Python for the moment). We have chosen a slightly different method from that of Racket. Where they can easily write `#lang`s, we chose to extend the parser and mix languages within the same file.

On 2022-11-14 09:23, Bradley Lucier wrote:
> https://racket.discourse.group/t/pyffi-use-python-from-racket/1362/8
> 
> There's been some interest in integrating Gambit with Python, here's an example of doing something similar in Racket.
> 
> Brad
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list



More information about the Gambit-list mailing list