Hosting IronScheme in a .net application

Sep 29, 2008 at 5:47 AM
Hi,

I want my .net application to use IronScheme so that I can use Scheme as a scripting language. The setup code goes something like

//Setup
ScriptDomainManager mgr = ScriptDomainManager.CurrentManager;
IronSchemeLanguageProvider slp = new IronSchemeLanguageProvider( mgr );
ScriptEngine se = slp.GetEngine( );

//Evaluation Loop
textAreaOuput.text += se.Evaluate( txtInput.text ).ToString() + "\n";


It works for something like "(+ 1 2)" and other simple arithmetic calculations and mathematical functions like "(sin 30)" but when I try to do "(define a 100)", I get an  IronScheme.Runtime.R6RS.CompoundCondition exception with message: "attempted to use undefined symbol". The same thing happens when I do an "(import something)".

Should I do something like load the ironscheme.boot.pp file (actually, I already did that but I still get the same problem)?
Coordinator
Sep 29, 2008 at 8:07 AM
Hi

You are pretty close :)

Like discovered, you need to load the ironscheme.boot.pp (or the dll) file. Currently, you need to add a little bit more for evaluation. (I will add an easy interface/class for this soon).

After loading the bootfile, you can evaluate by passing in: string.Format("(eval-r6rs {0})", "(+ 1 2)") .

This is needed for now, but should be all that is needed.

Hope this helps

Cheers

leppie
Sep 29, 2008 at 12:09 PM
Thanks for the information! Appreciated it.

Anyway, I think I forgot to ask on how to exactly load the ironscheme.boot.pp file (or the ironscheme.boot.dll one). The only thing I did is to invoke ScriptEngine::ExecuteFile( "ironscheme.boot.pp" ) but it seems to lose context after execution (so I'm still getting undefined symbols errors when I pass "(define a 100)"). In any case, any details on how exactly to load them?
Coordinator
Sep 29, 2008 at 12:13 PM


On Mon, Sep 29, 2008 at 1:09 PM, SnT2k <notifications@codeplex.com> wrote:

From: SnT2k

Thanks for the information! Appreciated it.

Anyway, I think I forgot to ask on how to exactly load the ironscheme.boot.pp file (or the ironscheme.boot.dll one). The only thing I did is to invoke ScriptEngine::ExecuteFile( "ironscheme.boot.pp" ) but it seems to lose context after execution (so I'm still getting undefined symbols errors when I pass "(define a 100)"). In any case, any details on how exactly to load them?


Hehe, I was not sure how to explain, but the following should work:

IronScheme.Runtime.Builtins.Load("~/ironscheme.boot.pp");

Note: Load will look for the pp file in the directory where IronScheme.dll is, or for an already compiled .dll file.

Now everything should be set up correctly, and you can 'eval' like above.

Cheers




Sep 29, 2008 at 3:55 PM
Edited Sep 29, 2008 at 3:56 PM
Hmm, I followed what you did and I could get some of the built-ins working except:

1) I still get an "Undefined symbol" exception for the "define" and "let" function; e.g. "(define foo 10)" fails. (ironic that the define is not defined lol)
2) When I use a lambda, I get a ContextSlot not available exception.

I have a feeling that I need to do something with the build directory in the IronSchemeConsole project (for the record, I copied every folder in the IronSchemeConsole project the remotely resembles Scheme source code and smacked it into my project and made sure that they're copied to the execution directory) but I still can't figure it out.
Sep 29, 2008 at 7:55 PM
Nevermind, I managed to figure out what was wrong. I did this:

se.Evaluate( String.Format( "(eval-r6rs {0})", tbxQuestion.Text )

instead of this:
se.Evaluate( String.Format( "(eval-r6rs '{0})", tbxQuestion.Text )

Note the single quote T_T...

Anyway, thanks for the advice!
Coordinator
Sep 29, 2008 at 8:02 PM
se.Evaluate( String.Format( "(eval-r6rs {0})", tbxQuestion.Text )

instead of this:
se.Evaluate( String.Format( "(eval-r6rs '{0})", tbxQuestion.Text )

Note the single quote T_T...

Anyway, thanks for the advice!
Oops :) My bad.
Coordinator
Jan 24, 2009 at 6:15 PM
I forgot to mention, but a few weeks/months ago, I fixed this issue, and one should not have to use the String.Format trick anymore (IIRC it will crash if you do!).

Cheers

leppie