You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: RainLisp/Docs/dotnet-integration.md
+54-42Lines changed: 54 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,42 @@ Your .NET system can specify an overall computational infrastructure and call Ra
11
11
12
12
> The .NET examples below are written in C# but any .NET language can be used.
13
13
14
+
## Evaluating RainLisp Expressions
15
+
`IInterpreter` defines `Evaluate` method overloads for evaluating RainLisp expressions, i.e. a program. These methods typically return an `IEnumerable<EvaluationResult>`
16
+
and the actual evaluation of each RainLisp expression occurs on a per request basis, i.e. while the enumeration is enumerated.
17
+
18
+
Let's see a simple example.
19
+
20
+
```csharp
21
+
usingRainLisp;
22
+
usingRainLisp.DotNetIntegration;
23
+
24
+
conststringRAIN_LISP_CODE=@"
25
+
(+ 1 1)
26
+
(- 10 2)
27
+
(* 4 7)
28
+
9";
29
+
30
+
varinterpreter=newInterpreter();
31
+
varresults=interpreter.Evaluate(RAIN_LISP_CODE);
32
+
33
+
foreach (varresultinresults)
34
+
{
35
+
Console.WriteLine(result.Number());
36
+
}
37
+
```
38
+
39
+
`RAIN_LISP_CODE` above contains the RainLisp expressions, each on a new line. Each expression is evaluated at runtime while `results` are enumerated in the `foreach` loop.
40
+
41
+
> Note that all subsequent examples use the `Execute` overloads which mirror the `Evaluate` ones. `Execute` methods evaluate all RainLisp expressions at once and
42
+
return the `EvaluationResult` of the last one.
43
+
14
44
## One-off Call
15
45
16
46
Let's suppose there is a custom RainLisp code that specifies a log file's name for a .NET system.
17
47
It first prints a message to the standard output and finally returns the log file name by concatenating some strings.
18
-
Conventionally, the RainLisp coder knows that the last thing they should return is a string.
48
+
Conventionally, the RainLisp coder knows that the last thing they should return is a string and this effectively reflects
49
+
the programming contract between the two systems.
19
50
20
51
```scheme
21
52
(define dt (utc-now))
@@ -29,21 +60,17 @@ The above code can be stored in a database or some other configuration medium. F
Notice that only the last evaluation result (LINQ's Last() method call) is taken into consideration, which is expected to be a `StringDatum`. This effectively reflects
45
-
the programming contract between the two systems.
46
-
47
74
> Note that exception handling in the C# example is omitted for brevity.
48
75
49
76
## Consecutive Calls
@@ -66,41 +93,32 @@ and the second one will call it with an appropriate value.
66
93
Once again, assume that the above code is loaded into `RAIN_LISP_CODE`.
0 commit comments