[plt-scheme] MzScheme and .NET

From: Chris Double (chris at double.co.nz)
Date: Mon Mar 17 03:04:20 EST 2003

"Pedro Pinto" <ppinto at cs.cmu.edu> writes:

> I have played around with the idea bit and was able to sketch out a
> tool that takes very simple .NET types and generates MzScheme
> extension code.

I do this with my .NET port of Goo. I include a utility (written in
C#) that uses reflection to examine the assembly and generate the Goo
wrapper code. Goo is a language not unlike Scheme in look and feel.

My information on the .NET port and source code to the wrapper
generator (in very ugly C# - it was my first ever C# program):


> However I have a feeling there will be significant semantic clashes ahead,
> including inheritance, namespaces, ref argument types, etc. I am not very
> familiar with this kind of problems so I was wondering if anyone has any
> references or comments on how to go about mapping statically typed OO
> constructs into scheme?

Places you could look for information on this might include those
libraries that allow calling Java from Scheme or Lisp.

In my Goo code I translate to a very low level API. Basically the name
of the method is converted to a Goo function with the namespace,
assembly and argument types appended to it. I append the argument
types due to overloading being allowed in .NET. Here's an example of
showing a message box:

  (use double/dotnet/system_windows_forms_messagebox) 
  (system-windows-forms-messagebox-show-string "Hello World!") 

An example reading a web page:

  (dv request 
    (system-net-webrequest-create-string "http://radio.weblogs.com/0102385/")) 
  (dv response (system-net-webrequest-getresponse request)) 
  (dv stream (system-net-webresponse-getresponsestream response)) 
  (dv buf (fab <vec> 8192)) 
  (fill! buf #space) 
  (dv count (system-io-stream-read-byteaa-int32-int32 stream buf 0 (len buf))) 
  (dv s (as <str> (sub buf 0 count))) 
  (msg out "%s\n" s) 
  (system-io-stream-close stream) 

'dv' defines a variable. (fab <vec> 8192) Creates a vector of size
8192. (sub buf 0 count) returns a substring and (as <str> ...)
converts it to a string.

I have not yet approached inheriting from .NET classes but I'd
probably approach it in the same manner as people having been using to
wrap things like Java in Lisp. If you look through c.l.l. or
comp.lang.dylan you'll see references to many approaches to this in
the past.

How have you done your .NET mapping across to Scheme? 


Posted on the users mailing list.