C# Calling IronScheme

Feb 25, 2010 at 9:12 PM
Edited Feb 27, 2010 at 6:58 PM

How can I call a function I wrote in IronScheme from C#? In Clojure, I can write something like:

 

(ns com.ociweb.clj.Demo
  (:gen-class
   :methods [#^{:static true} [getMessage [String] String]]))

# Note the hyphen at the beginning of the function name!
(defn -getMessage [name]
  (str "Hello, " name "!"))

 

and then call it from Java like this:

 

import com.ociweb.clj.Demo; // class created by compiling Clojure source file

public class Main {

    public static void main(String[] args) {
        String message = Demo.getMessage("Mark");
        System.out.println(message);
    }
}

 

Is there a way to do the same thing with IronScheme and C# ? Are there plans to create something like Clojure gen-class?

Feb 27, 2010 at 7:22 PM

Maybe by calling Reflection.Emit with IronScheme? are there some examples of that somewhere?

Feb 27, 2010 at 7:35 PM

I found this code example after searching in Google: IronScheme Reflection Emit.

Is this an example of how to define a class (inside an assembly) in Iron Scheme?:

 

(define myhello
  (ilasm
    (assembly myhello)
    (module myhello.dll
      (type foo public
        (method bar (public static) (System.Int32 => System.Int32)
          (locals)
          ldarg.0
          ret)
        (method baz (public static) (=> System.Int32)
          (locals)
          (ldc.i4 1)
          ret)
          ))))

 

 

Looks very low level... Anyone on this forum knows a of higher level example or guide on how to do this?

Coordinator
Feb 27, 2010 at 7:53 PM

Hi

The code in your above post was an experiment. I kinda hit a wall on it, and need to think about it a lot more  :(

As IronScheme currently uses an incremental compiler approach, all code is compiled to memory, with the exception of the bootfile.

I hope to someday make it fully compiled (I have experimented with some ideas).

For now the best way to call Scheme from C# is to the approaches shown in the documentation.

If you are using .NET 4, you can try using (and improving) the 'dynamic' proof of concept I did.

I also hope to improve on this once .NET 4 goes RTM.

Cheers

leppie