Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling LISP or SCHEME from .NET/C#

Tags:

lisp

scheme

In my existing software I have an implementation of genetic programing using home grown decission making tree that is able to apply basic logic operators (AND OR NOT) in some boolean data that are provided to it in a form of an array. The platform I am using is .NET / C# with SQLServer back end. Looking for ways to improve the performance of my genetic program I concluded that I need almost all the additional functionality that comes with a functional language and I believe Scheme or to a lesser extend LISP are the best solutions for it unless I want to implement features like COND, IF, comparisson operators etc myself extending the existing implementation.

My question to the forum is if there is any efficient way to call Scheme (or LISP) from a .NET application passing data back and front in some array form. If this is not possible, do you thing that it will better just to bite the bullet and implement it from scratch or I should look for alternative ways, like for example communicating using a text file?

like image 933
JohnP Avatar asked Jul 28 '10 20:07

JohnP


3 Answers

There is an R6RS compliant Scheme implementation for the DLR called IronScheme. Since IronScheme uses the DLR, it can be embedded into any .NET application using the standardized DLR embedding APIs in exactly the same way that you would embed, say, IronRuby or IronPython:

dynamic Scheme = new SchemeEnvironment();
var list = Scheme.list;
var map = Scheme.map;
// and so on

The full snippet can be found in a blog post by IronScheme's author, leppie. It also shows how to pass a C# lambda to a Scheme higher-order function and other cool stuff.

like image 182
Jörg W Mittag Avatar answered Nov 05 '22 11:11

Jörg W Mittag


Unless you go with IronScheme (above), I'd probably use something like ZeroMQ (which has both Common Lisp and .Net drivers) to pass messages between the two systems.

like image 32
Shaun Avatar answered Nov 05 '22 09:11

Shaun


I built a lightweight, embeddable Scheme-like language interpreter exactly for the purpose of complex and re-usable configuration. It has a small footprint (~1500 line of code) and does not introduce any other dependency to your application.

I open-sourced it from work. It's called schemy. Here is also an example application demonstrating how to use it in really complex way.

I also provided some detailed motivation behind building it for work in this stackoverflow answer.

Hope it helps:)

like image 23
KFL Avatar answered Nov 05 '22 09:11

KFL