missinglisp 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/missinglisp.rb +37 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae3e777539c93908862948b929c853cabb00355c4c2e914cf6d3a9c41582f48
|
4
|
+
data.tar.gz: 956586736b5fd59d05c5e69e258d5df6765baf2cffcfc04dc817bd545078b891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad002ea51f96a49067e473e62b216fcaa0dbebd90d2c7154c6a9d7c93c5e994c6e8b7d21a27d9d677511ac50e28ba39e3f447b411d8582cbcd9460d32b1a0675
|
7
|
+
data.tar.gz: 89e117cb00041f94d2b72d00fe5b9a0eb9f50f34658d1d5fdc992b30c2410b76a7ff0ec5ed53754332bb26ab10d8b89331fa1bf89152b8e1695e0bcd63826687
|
data/lib/missinglisp.rb
CHANGED
@@ -16,7 +16,21 @@ class Lisp
|
|
16
16
|
gt: ->(a, b, *) { a > b },
|
17
17
|
geq: ->(a, b, *) { a >= b },
|
18
18
|
|
19
|
+
length: ->(l, *) { l.length },
|
20
|
+
|
21
|
+
# string
|
22
|
+
aref: ->(s, at, *) { s[at] },
|
23
|
+
concatenate: ->(_type, *ls) { ls.reduce(:+) },
|
24
|
+
|
25
|
+
# char
|
26
|
+
codeChar: ->(c, *) { c.chr },
|
27
|
+
charCode: ->(c, *) { c.ord },
|
28
|
+
|
29
|
+
readLine: ->(*) { $stdin.readline.chomp },
|
30
|
+
|
19
31
|
p: ->(*ls) { p ls },
|
32
|
+
print: ->(*ls) { p ls },
|
33
|
+
writeLine: ->(s, *) { puts s },
|
20
34
|
|
21
35
|
t: true,
|
22
36
|
nil: []
|
@@ -25,6 +39,7 @@ class Lisp
|
|
25
39
|
|
26
40
|
def eval(exp, env)
|
27
41
|
return exp if exp.is_a? Numeric
|
42
|
+
return exp if exp.is_a? String
|
28
43
|
return env[exp] if exp.is_a? Symbol
|
29
44
|
|
30
45
|
# list
|
@@ -64,7 +79,6 @@ class Lisp
|
|
64
79
|
|
65
80
|
res = nil
|
66
81
|
exp.each do |stmt|
|
67
|
-
# p stmt
|
68
82
|
res = self.eval(stmt, env)
|
69
83
|
end
|
70
84
|
|
@@ -113,9 +127,12 @@ class Lisp
|
|
113
127
|
res = []
|
114
128
|
cur = ''
|
115
129
|
is_reading_digit = false
|
130
|
+
is_reading_string = false
|
116
131
|
s.each_char do |c|
|
117
132
|
case c
|
118
133
|
when '_'
|
134
|
+
cur += ' ' and next if is_reading_string
|
135
|
+
|
119
136
|
if cur != ''
|
120
137
|
if is_reading_digit
|
121
138
|
res.push cur.to_i
|
@@ -154,6 +171,25 @@ class Lisp
|
|
154
171
|
end
|
155
172
|
|
156
173
|
res.push :J
|
174
|
+
when 'Q'
|
175
|
+
if is_reading_string
|
176
|
+
res.push cur
|
177
|
+
cur = ''
|
178
|
+
is_reading_string = false
|
179
|
+
next
|
180
|
+
elsif is_reading_digit
|
181
|
+
res.push cur.to_i
|
182
|
+
cur = ''
|
183
|
+
is_reading_digit = false
|
184
|
+
is_reading_string = true
|
185
|
+
next
|
186
|
+
end
|
187
|
+
|
188
|
+
if cur != ''
|
189
|
+
cur += 'Q'
|
190
|
+
else
|
191
|
+
is_reading_string = true
|
192
|
+
end
|
157
193
|
when '0'..'9'
|
158
194
|
cur += c and next if cur != ''
|
159
195
|
|