Re: [capi-sig] Python to Scheme type conversion in C?

[please always reply to the list]
Jason Baker, 31.05.2010 21:45:
Since you didn't provide the link (and "mzscheme ffi" doesn't get me anything that looks right at first sight), am I right in guessing that you might be referring to this?
http://download.plt-scheme.org/doc/351/html/foreign/
Why not write a type checking cascade in plain C or Cython?
Scheme is a strictly typed language, though, and your Scheme code won't run with (or even accept) arbitrary Python input value types, just like your Python code won't run with arbitrary Scheme value types as input. So you have to draw the line somewhere. And since you are using an FFI, which, I assume, passes through C anyway, you might just as well restrict your glue code to suitable types.
Stefan

On Mon, May 31, 2010 at 3:06 PM, Stefan Behnel <stefan_ml@behnel.de> wrote:
[please always reply to the list]
Sorry. :-/
That's an older version of the docs, but yes. Here's a more recent link: http://docs.plt-scheme.org/foreign/index.html
I suppose I could, but I'd rather write it in pure Scheme or Python if at all possible. If that's not efficient enough, I can look into adding C into the mix.
I suppose I could use tagged pointers[1], but I was wanting something more generic (in other words, an interface that automatically does the right thing). Perhaps I'm biting off more than I can chew though.
[1] http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3at...)

Jason Baker, 31.05.2010 22:31:
You could build a dict that maps any combination of a builtin Python type and a Scheme type to a way to convert the first to the second. That might even be faster than a type checking cascade in C. Structured types would fall back to the standard Python type conversion rules.
Stefan

On Mon, May 31, 2010 at 3:06 PM, Stefan Behnel <stefan_ml@behnel.de> wrote:
[please always reply to the list]
Sorry. :-/
That's an older version of the docs, but yes. Here's a more recent link: http://docs.plt-scheme.org/foreign/index.html
I suppose I could, but I'd rather write it in pure Scheme or Python if at all possible. If that's not efficient enough, I can look into adding C into the mix.
I suppose I could use tagged pointers[1], but I was wanting something more generic (in other words, an interface that automatically does the right thing). Perhaps I'm biting off more than I can chew though.
[1] http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3at...)

Jason Baker, 31.05.2010 22:31:
You could build a dict that maps any combination of a builtin Python type and a Scheme type to a way to convert the first to the second. That might even be faster than a type checking cascade in C. Structured types would fall back to the standard Python type conversion rules.
Stefan
participants (2)
-
Jason Baker
-
Stefan Behnel