-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLispArray.cs
More file actions
109 lines (93 loc) · 2.01 KB
/
LispArray.cs
File metadata and controls
109 lines (93 loc) · 2.01 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Numerics;
using System.Collections.Generic;
namespace libQCLISP
{
public class LispArray : ILispValue
{
public List<ILispValue> value;
public bool force_eval=true;
public LispArray (List<ILispValue> value)
{
this.value = value;
}
public ELispType getType()
{
return ELispType.LispValue;
}
public BigInteger getInteger()
{
if (value.Count == 0)
return 0;
return value[0].getInteger();
}
public string getString()
{
string print = "";
print += force_eval ? "(" : "'(";
for (int idx = 0; idx < value.Count; idx++) {
print += value [idx].getString ();
if (idx != value.Count - 1)
print += " ";
}
print+=')';
return print;
}
public double getFloating()
{
if (value.Count == 0)
return 0.0;
return value[0].getFloating();
}
public bool getBoolean()
{
if (value.Count == 0)
return false;
return value[0].getBoolean();
}
public char getCharacter()
{
if (value.Count == 0)
return '\0';
return value[0].getCharacter();
}
public T getN<T>()
{
throw new NotLispValueException();
}
public ILispValue eval()
{
if (value.Count == 0)
return new LispArray(new List<ILispValue>());
if (force_eval) {
if(value [0].getType()==ELispType.Native)
return ((ILispNative)value [0]).execute (this);
if (value [0].getType () == ELispType.LispValue) {
var first = value [0].eval ();
if (first.getType() != ELispType.Native) {
LispArray ret = new LispArray (new List<ILispValue>(value.Count));
ret.value.Add (first);
for(int i=1;i<value.Count;i++)
ret.value.Add(value [i].eval ());
return ret;
}else
return ((ILispNative)first).execute (this);
}
}
return this;
}
public ILispValue this[int idx]
{
get{return value [idx];}
set{throw new Exception ("Trying to alter immutable data"); }
}
public int getSize()
{
return value.Count;
}
public List<ILispValue> getInner()
{
return value;
}
}
}