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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
using System;
using System.Collections.Generic;
using MalVal = Mal.types.MalVal;
using MalConstant = Mal.types.MalConstant;
using MalInteger = Mal.types.MalInteger;
using MalString = Mal.types.MalString;
using MalList = Mal.types.MalList;
using MalFunction = Mal.types.MalFunction;
namespace Mal {
public class core {
static MalConstant Nil = Mal.types.Nil;
static MalConstant True = Mal.types.True;
static MalConstant False = Mal.types.False;
// String functions
static public MalFunction pr_str = new MalFunction(
a => new MalString(printer._pr_str_args(a, " ", true)) );
static public MalFunction str = new MalFunction(
a => new MalString(printer._pr_str_args(a, "", false)) );
static public MalFunction prn = new MalFunction(
a => {
Console.WriteLine(printer._pr_str_args(a, " ", true));
return Nil;
} );
static public MalFunction println = new MalFunction(
a => {
Console.WriteLine(printer._pr_str_args(a, " ", false));
return Nil;
} );
// Sequence functions
static public MalFunction list_Q = new MalFunction(
a => a[0].GetType() == typeof(MalList) ? True : False);
static public Dictionary<string, MalVal> ns =
new Dictionary<string, MalVal> {
{"=", new MalFunction(
a => Mal.types._equal_Q(a[0], a[1]) ? True : False)},
{"pr-str", pr_str},
{"str", str},
{"prn", prn},
{"println", println},
{"<", new MalFunction(a => (MalInteger)a[0] < (MalInteger)a[1])},
{"<=", new MalFunction(a => (MalInteger)a[0] <= (MalInteger)a[1])},
{">", new MalFunction(a => (MalInteger)a[0] > (MalInteger)a[1])},
{">=", new MalFunction(a => (MalInteger)a[0] >= (MalInteger)a[1])},
{"+", new MalFunction(a => (MalInteger)a[0] + (MalInteger)a[1])},
{"-", new MalFunction(a => (MalInteger)a[0] - (MalInteger)a[1])},
{"*", new MalFunction(a => (MalInteger)a[0] * (MalInteger)a[1])},
{"/", new MalFunction(a => (MalInteger)a[0] / (MalInteger)a[1])},
{"list", new MalFunction(a => new MalList(a.getValue()))},
{"list?", list_Q},
{"first", new MalFunction(a => ((MalList)a[0]).nth(0))},
{"rest", new MalFunction(a => ((MalList)a[0]).rest())},
{"count", new MalFunction(
a => new MalInteger(((MalList)a[0]).size()))},
{"empty?", new MalFunction(
a => ((MalList)a[0]).size() == 0 ? True : False)},
};
}
}
|