Suitability for real-time applications

Mar 25, 2013 at 10:43 AM
I have been looking for an implementation of Scheme on the CLR that would be suitable for real-time applications. As a hobby I was going to experiment using Scheme for game development. It would be really cool to be able to use a .NET implementation since then I would have access to the amazing MonoGame!
Coordinator
Mar 25, 2013 at 11:27 AM
It depends on your definition of 'real-time' :)

If you feel C# is real-time, then yes, IronScheme would fall into the same category as long as you dont use `eval` during runtime.

But almost any language with a JIT compiler is not really strictly real-time :)


On Mon, Mar 25, 2013 at 11:43 AM, sonelliot <notifications@codeplex.com> wrote:

From: sonelliot

I have been looking for an implementation of Scheme on the CLR that would be suitable for real-time applications. As a hobby I was going to experiment using Scheme for game development. It would be really cool to be able to use a .NET implementation since then I would have access to the amazing MonoGame!

Read the full discussion online.

To add a post to this discussion, reply to this email (IronScheme@discussions.codeplex.com)

To start a new discussion for this project, email IronScheme@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
http://codeplex.com/IronScheme
http://xacc.wordpress.com
Mar 25, 2013 at 1:34 PM
Haha, yes I guess you are right, JIT-compiled languages aren't really real-time, or so-to-speak. Probably what I was after was an indication of it's runtime performance in comparison to C#, which would be the language I would typically be using to work with MonoGame.
Apr 5, 2013 at 5:15 AM
Hi Leppie,

As a follow-up, I've been doing some prototyping embedding IronScheme into a running game and using it to execute code and commands at run-time. The problem I am now struggling with is sharing objects from the running application in the interactive Scheme environment. I understand that you can use clr-new to create instances of CLR types. Is it possible to create an object in C# and then share it with the IronScheme environment?
Coordinator
Apr 5, 2013 at 5:22 AM
Edited Apr 5, 2013 at 5:24 AM
Hi

There are various ways to share data.

If you want to to pass the an instance (of anything/object) from C#, you can do:
"(some-proc {0})".Eval(instance);
some-proc will receive the instance as is. {0} is effectively bound to that instance.

If you want to get some data from Scheme, you can just call a normal CLR method/property:
(let ((o (clr-static-call Foo Bar))) ...)
If you have a different scenario, let me know :)

Cheers

leppie
Apr 5, 2013 at 6:45 AM
Thanks Leppie, that did the trick. I did come across one irregularity. I had to do this to get it to work:
"(define some-object '())".Eval();
"(set! some-object {0})".Eval(instance);
When I tried to pass the CLR object to the define evaluation it threw this error:
{&message: "no expression in body"
&syntax:
  form: ()
  subform: #f
}
Not sure why it did this? It seems like a reasonable call to me..
Coordinator
Apr 5, 2013 at 6:49 AM
Edited Apr 5, 2013 at 7:04 AM
Yes, define will be problematic with arguments. Will see if I can fix that :)

The better way would be to use parameters, and just set the value. Eg:

In Scheme:
(define some-object (make-parameter #f))
From C#:
"(some-object {0})".Eval(instance);
Then in Scheme you would use it like:
(let ((o (some-object))) ...)
This way Scheme knows about the variable.
Apr 6, 2013 at 4:14 AM
Edited Apr 6, 2013 at 4:17 AM
Thanks Leppie that works great. I can now control the game at runtime from an IronScheme console!

In my little console application that uses the InteractionService I have been catching exceptions and printing them to the output. This works well for fairly well-known problems like undefined symbols, which typically print out something like this:
&undefined
&message: "attempted to use undefined symbol"
&irritants: (beh)
But I also see a lot of SyntaxErrorException being thrown which are spit out a large stack trace and aren't very helpful. Do you have any words of wisdom for my approach here? I am currently in the process of building IronScheme from source so that I can attach the debugger and break when the exceptions are being thrown. I'm hoping this will help me discover what I've done wrong and potentially if there is a way of making those error messages a bit nicer.

If you're interested, this is an example issue:
(import (rnrs) (ironscheme clr))
(let ((str (clr-new String "")))
  str)
If I run this with the provided IronScheme console I see:
Unhandled CLR exception during evaluation:
CLR Exception: System.InvalidCastException
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Char[]'.
   at eval-core(031).Initialize(CodeContext )
   at #.ironscheme.exceptions::dynamic-wind(Object in, Object proc, Object out)
   at #.ironscheme.exceptions::dynamic-wind(Object in, Object proc, Object out)
   at IronScheme.Runtime.Builtins.CallWithCurrentContinuation(Object fc1)
   at IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(Object handler, Object thunk)
Which is quite helpful because it tells me what went wrong. But running it with my remote console app, I see:
Microsoft.Scripting.SyntaxErrorException: Exception of type 'Microsoft.Scripting.SyntaxErrorException' was thrown.
   at Microsoft.Scripting.LanguageContext.CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
   at Microsoft.Scripting.Hosting.ScriptEngine.CompileSourceUnit(SourceUnit sourceUnit, IScriptModule module)
   at Microsoft.Scripting.Hosting.ScriptEngine.CompileExpression(String expression, IScriptModule module)
   at IronScheme.RuntimeExtensions.EvalWithEnvironment(String expr, String importspec, Object[] args)
   at IronScheme.Remoting.Server.InteractionService.EvalInternal(String expr, String importspec, Object[] args)
Which is less useful.

Edit: I'm thinking that using the InteractionService might not be the best way to go. Would it be difficult to modify the provided IronScheme console to connect to a remote server?
Coordinator
Apr 6, 2013 at 9:42 AM
Edited Apr 6, 2013 at 9:46 AM
I managed to recreate the error :)

What effectively happens is that you are calling:
ii.Eval("(import (ironscheme clr)) (let ((str (clr-new String \"\"))) str");
The evaluator can only handle a single (S) expression and you are passing 2 in.

This is easy to handle. Just wrap your input string with the following:
input = string.Format("(begin {0} \n)", input);
My previous assumption was incorrect :)
Apr 8, 2013 at 3:45 AM
Thanks Leppie. That works nicely. I also discovered that my console app couldn't handle multiple lines of input (doh!) I made it read input a little bit more intelligently, looking for an matching number of open and close brackets before submitting the input to the evaluator.