-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (23 loc) · 818 Bytes
/
Program.cs
File metadata and controls
35 lines (23 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Diagnostics;
using Mana;
var m = new Mana.Mana();
// Mana calling Native
Value Add1(Env<Value> env, List<Value> args) =>
args switch
{
[Value.Num a, Value.Num b] => Value.NewNum(a.AsNum + b.AsNum),
_ => throw new ArgumentException("Arguments must be numbers")
};
var Add2 = (double a, double b) => a + b;
m.setValue("add1", Value.NewFuncClosure(Add1));
m.setValue("add2", m.toValue<Func<double, double, double>>(Add2));
m.setValue("x", Value.NewNum(2));
m.setValue("y", Value.NewNum(3));
var res1 = m.run("add1 x y");
var res2 = m.run("add2 x y");
Debug.Assert(res1.AsNum == 5);
Debug.Assert(res2.AsNum == 5);
// Native calling Mana
m.run("let addM = {|x, y| x + y}");
var resM = m.call("addM", [Value.NewNum(2), Value.NewNum(3)]);
Debug.Assert(resM.AsNum == 5);