How to get IronScheme function return in C# (Visual Studio)

270 views Asked by At

I am making a program in C# (using Visual Studio) which uses IronScheme, and this is a snippet of code I have.

exp = "(car '('(1 2 3) 4 5 6))";
System.Console.WriteLine(exp.Eval());

Basically, I want to get the first element of that list, which is another list (1 2 3). My problem is I don't know how to obtain the actual list of number. In this example, I'm printing the result of the Eval(), which prints:

IronScheme.Runtime.Cons

If I convert it to string, I get the same result. And any other type cast/conversion prints the same thing

System.Console.WriteLine(exp.Eval().ToString()); 
// Also prints "IronScheme.Runtime.Cons"

How do I get the values of that list, as C# list List<>?

1

There are 1 answers

1
leppie On

Cons implements IEnumerable.

One problem you have is the quoted list inside an already quoted list. I am not sure if this what you want, but I am removing it for the example:

var exp = "(car '((1 2 3) 4 5 6))";
var result = exp.Eval<Cons>(); // eval and cast => (1 2 3)

var list = result.Cast<int>().ToList(); 

Protip: You can use Cons.PrettyPrint to see the content expanded in a more readable format.