Interoperability between Racket & Chez Scheme

91 views
Skip to first unread message

Brian Adkins

unread,
Jul 23, 2019, 8:14:56 PM7/23/19
to Racket Users
With the Racket on Chez Scheme implementation, how interoperable are Racket and Chez? Is it possible for Racket functions to call Chez functions (or vice versa) directly w/o using a FFI? If so, can you point me to some documentation? If not, how difficult would it be to make this happen?

Thanks,
Brian

Matthew Flatt

unread,
Jul 23, 2019, 8:52:36 PM7/23/19
to Brian Adkins, Racket Users
Chez Scheme functions work as Racket functions. A Racket function works
as a Chez Scheme function unless it accepts keyword arguments, is an
impersonator, or is an instance of a structure type that implemented
`prop:procedure`.

The easiest way to get a Chez Scheme primitive is to use the
`get-primitive` function from Sam's `get-primitive` package:

https://github.com/samth/get-primitive


Racket pairs, symbols, etc., are Chez Scheme pairs, symbols, etc., so
you can get Chez Scheme's `eval` and easily start evaluating Chez
Scheme expressions.

Brian Adkins

unread,
Jul 23, 2019, 9:08:46 PM7/23/19
to Racket Users
Thanks. I just realized I wasn't very clear. 

I was primarily referring to user defined functions. For example, if I wrote a Chez Scheme library, how would I use that from w/in some Racket code I wrote?

Matthew Flatt

unread,
Jul 23, 2019, 9:32:16 PM7/23/19
to Brian Adkins, Racket Users
At Tue, 23 Jul 2019 18:08:46 -0700 (PDT), Brian Adkins wrote:
> For example, if I wrote a Chez Scheme library, how would I use that
> from w/in some Racket code I wrote?

After you get Chez Scheme's `eval`, you can do whatever you need at the
Chez Scheme level. That includes loading Chez Scheme libraries and
evaluating Chez Scheme expressions that produce functions. When you get
a function back from Chez Scheme's `eval`, you can call it from Racket.

Now that I think about it more, you'll have to take some care running
Chez Scheme functions from Racket, because there are lots of ways to
break Racket's assumptions at the Chez Scheme level. Perhaps the most
significant requirement that is you should call Chez Scheme functions
only under `call-with-system-wind` (which you'd have to get via
`get-primitive`), because Racket threads and exceptions do not by
default work with Chez Scheme's `dynamic-wind`.

There are probably other things to pin down, and some of it could be
packaged into a better FFI for calling Chez Scheme from Racket.

Hendrik Boom

unread,
Jul 24, 2019, 5:17:40 PM7/24/19
to Racket Users
On Tue, Jul 23, 2019 at 06:52:32PM -0600, Matthew Flatt wrote:
> At Tue, 23 Jul 2019 17:14:56 -0700 (PDT), Brian Adkins wrote:
> > With the Racket on Chez Scheme implementation, how interoperable are Racket
> > and Chez? Is it possible for Racket functions to call Chez functions (or
> > vice versa) directly w/o using a FFI? If so, can you point me to some
> > documentation? If not, how difficult would it be to make this happen?
>
> Chez Scheme functions work as Racket functions. A Racket function works
> as a Chez Scheme function unless it accepts keyword arguments, is an
> impersonator, or is an instance of a structure type that implemented
> `prop:procedure`.

What about immutable lists? Can Chez Scheme operations mutate them?

>
> The easiest way to get a Chez Scheme primitive is to use the
> `get-primitive` function from Sam's `get-primitive` package:
>
> https://github.com/samth/get-primitive
>
>
> Racket pairs, symbols, etc., are Chez Scheme pairs, symbols, etc., so
> you can get Chez Scheme's `eval` and easily start evaluating Chez
> Scheme expressions.
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/5d37abd2.1c69fb81.3c40d.2941SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Reply all
Reply to author
Forward
0 new messages