Skip to content

CommonLarcenyMarshalling

Felix S. Klock II edited this page Jul 28, 2013 · 2 revisions

= Data Conversions Between Common Larceny and Other .NET Languages =

The basic conversions from Scheme to other .NET languages are implemented by clr/default-marshal-out (note spelling).

The basic conversions from other .NET languages to Scheme are implemented by clr/default-marshal-in (note spelling).

Both are defined in lib/MzScheme/dotnet.sch, which no longer has anything to do with MzScheme.

The class-name and class-of procedures can be applied to values that are not converted into a usual Scheme value by clr/default-marshal-in.

The clr/%type-as-string procedure can be applied to the result of clr/default-marshal-out (FIXME: Except it doesn't work on null).

Conversions From Common Larceny to .NET

As implemented by clr/default-marshal-out.


#!rst

+---------------------+------------------------------+
|   Scheme Type       | Corresponding .NET Type(s)   |
+=====================+==============================+
| boolean             | System.Boolean               |
+---------------------+------------------------------+
| char                | System.Char                  |
+---------------------+------------------------------+
| string              | System.String                |
+---------------------+------------------------------+
| fixnum              | System.Int32                 |
+---------------------+------------------------------+
| inexact real        | System.Double                |
+---------------------+------------------------------+
| empty list          | null                         |
+---------------------+------------------------------+
| bytevector          | System.Byte[]                |
+---------------------+------------------------------+
| ALL CONVERSIONS BELOW THIS LINE ARE UNIMPLEMENTED  |
+---------------------+------------------------------+
| complex             | (unless real)                |
+---------------------+------------------------------+
| exact rational      | (unless fixnum)              |
+---------------------+------------------------------+
| procedure           | none                         |
+---------------------+------------------------------+
| pair                | none                         |
+---------------------+------------------------------+
| list                | none                         |
+---------------------+------------------------------+
| symbol              | none                         |
+---------------------+------------------------------+
| vector              | System.Array                 |
|                     | (maybe System.Vector?)       |
+---------------------+------------------------------+

For procedures, the closest match would be System.Delegate or System.MulticastDelegate.

Conversions From .NET to Common Larceny

As implemented by clr/default-marshal-in.


#!rst

+---------------------+------------------------------+
|   .NET Type         | Corresponding Scheme Type(s) |
+=====================+==============================+
| System.Boolean      | boolean                      |
+---------------------+------------------------------+
| System.Char         | character                    |
+---------------------+------------------------------+
| System.String       | string                       |
+---------------------+------------------------------+
| System.Byte         | exact integer                |
+---------------------+------------------------------+
| System.SByte        | exact integer                |
+---------------------+------------------------------+
| System.Int16        | exact integer                |
+---------------------+------------------------------+
| System.UInt16       | exact integer                |
+---------------------+------------------------------+
| System.Int32        | exact integer                |
+---------------------+------------------------------+
| System.UInt32       | exact integer                |
+---------------------+------------------------------+
| System.Int64        | exact integer                |
+---------------------+------------------------------+
| System.UInt64       | exact integer                |
+---------------------+------------------------------+
| System.Single       | inexact real                 |
+---------------------+------------------------------+
| System.Double       | inexact real                 |
+---------------------+------------------------------+
| null                | empty list                   |
+---------------------+------------------------------+
| System.Byte[]       | bytevector                   |
+---------------------+------------------------------+
| System.Array        | vector                       |
+---------------------+------------------------------+
| enum (FIXME)        | exact integer                |
+---------------------+------------------------------+
| ALL CONVERSIONS BELOW THIS LINE ARE UNIMPLEMENTED  |
+---------------------+------------------------------+
| System.Decimal      |                              |
+---------------------+------------------------------+

Notes

.NET methods that consume numeric arguments do not work unless the right type of numbers are used. Specifically, if a method expects a double, and an integral scheme number is supplied, it will not work. (System.Math.Sqrt 4) does not work, whereas (System.Math.Sqrt 4.0) does.

The type System.Decimal isn't converted properly to a number in scheme.

It appears as though when a .NET method produces an array it is automatically translated to a vector so the scheme world can understand it, but there is no implicit conversion going the other way. SOME methods that expect arrays as input do not function when given vectors as input. However, SOME do.

(System.String.Join "-" (vector "foo" "bar")) works.

Someone wrote that


(System.IO.File.WriteAllBytes "C:\TEMP\temp-file.txt" (System.IO.File.ReadAllBytes "C:\TEMP\original-file.txt"))

does not work, but both System.IO.File.ReadAllBytes and System.IO.File.WriteAllBytes work for Will.

Clone this wiki locally