goodguide-gibbon 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/lib/goodguide/gibbon/version.rb +1 -1
- data/lib/goodguide/gibbon.rb +71 -43
- data/vendor/gibbon/lib/gibbon.browser.dev.js +312 -236
- data/vendor/gibbon/lib/gibbon.browser.js +312 -236
- metadata +4 -4
data/Gemfile
CHANGED
data/lib/goodguide/gibbon.rb
CHANGED
@@ -4,6 +4,47 @@ require 'pathname'
|
|
4
4
|
|
5
5
|
module GoodGuide
|
6
6
|
module Gibbon
|
7
|
+
module Util
|
8
|
+
extend self
|
9
|
+
def hash_to_ruby(js_hash)
|
10
|
+
return nil unless js_hash
|
11
|
+
|
12
|
+
ruby_hash = {}
|
13
|
+
iterator = lambda { |this, k, v|
|
14
|
+
ruby_hash[k] = obj_to_ruby(v)
|
15
|
+
}
|
16
|
+
|
17
|
+
js_hash[:each].methodcall js_hash, iterator
|
18
|
+
|
19
|
+
ruby_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def hash_to_js(ruby_hash)
|
23
|
+
js_hash = gibbon[:Hash].new
|
24
|
+
ruby_hash.each do |k, v|
|
25
|
+
js_hash.set(k, v)
|
26
|
+
end
|
27
|
+
js_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def obj_to_ruby(o)
|
31
|
+
case o
|
32
|
+
when V8::Array
|
33
|
+
o.map { |x| obj_to_ruby(x) }
|
34
|
+
when V8::Object
|
35
|
+
o = o.asJSON if o.respond_to? :asJSON
|
36
|
+
|
37
|
+
out = {}
|
38
|
+
o.each do |k, v|
|
39
|
+
out[k] = obj_to_ruby(v)
|
40
|
+
end
|
41
|
+
out
|
42
|
+
else
|
43
|
+
o
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
7
48
|
def self.root
|
8
49
|
Pathname.new(__FILE__).dirname.parent.parent
|
9
50
|
end
|
@@ -58,6 +99,12 @@ module GoodGuide
|
|
58
99
|
class QueryError < StandardError; end
|
59
100
|
|
60
101
|
class RuntimeError < StandardError; end
|
102
|
+
class MissingData < RuntimeError
|
103
|
+
attr_reader :query_type, :id, :annotations
|
104
|
+
def initialize(type, id, annotations)
|
105
|
+
@query_type, @id, @annotations = type, id, annotations
|
106
|
+
end
|
107
|
+
end
|
61
108
|
|
62
109
|
class Program
|
63
110
|
def self.compile(source, info={})
|
@@ -100,7 +147,7 @@ module GoodGuide
|
|
100
147
|
self.semantics, entity_id, runtime_client.to_js
|
101
148
|
)
|
102
149
|
|
103
|
-
raise
|
150
|
+
raise error if error
|
104
151
|
values
|
105
152
|
end
|
106
153
|
end
|
@@ -120,7 +167,7 @@ module GoodGuide
|
|
120
167
|
|
121
168
|
private
|
122
169
|
def get_query(type)
|
123
|
-
query = self.class.queries[type]
|
170
|
+
query = self.class.queries[type.to_s]
|
124
171
|
raise "no such query #{type}" if query.nil?
|
125
172
|
query
|
126
173
|
end
|
@@ -130,8 +177,8 @@ module GoodGuide
|
|
130
177
|
cb = args.pop
|
131
178
|
err, val = begin
|
132
179
|
[nil, send(method, *args)]
|
133
|
-
rescue QueryError => e
|
134
|
-
[e
|
180
|
+
rescue QueryError, RuntimeError => e
|
181
|
+
[e, nil]
|
135
182
|
end
|
136
183
|
|
137
184
|
cb.call(err, val)
|
@@ -140,6 +187,8 @@ module GoodGuide
|
|
140
187
|
end
|
141
188
|
|
142
189
|
class StaticClient < AbstractClient
|
190
|
+
include Util
|
191
|
+
|
143
192
|
def query_error!(*a)
|
144
193
|
raise QueryError.new(*a)
|
145
194
|
end
|
@@ -147,7 +196,7 @@ module GoodGuide
|
|
147
196
|
def analyze_query(input_id, query, t)
|
148
197
|
query_impl = get_query(query.type)
|
149
198
|
analysis = instance_exec(input_id, query.name, t, &query_impl)
|
150
|
-
analysis[:annotations][
|
199
|
+
analysis[:annotations]['_query_type'] = query.type
|
151
200
|
analysis
|
152
201
|
end
|
153
202
|
|
@@ -157,17 +206,33 @@ module GoodGuide
|
|
157
206
|
end
|
158
207
|
|
159
208
|
class RuntimeClient < AbstractClient
|
209
|
+
include Util
|
160
210
|
def perform_query(id, annotations, v)
|
161
|
-
|
211
|
+
annotations = obj_to_ruby(annotations)
|
212
|
+
|
213
|
+
query_type = annotations.delete('_query_type')
|
214
|
+
|
215
|
+
# stash this data in case missing_data! is called
|
216
|
+
@last_query_type = query_type
|
217
|
+
@last_annotations = annotations
|
218
|
+
@last_id = id
|
219
|
+
|
220
|
+
query = get_query(query_type)
|
162
221
|
instance_exec(id, annotations, v, &query)
|
163
222
|
end
|
164
223
|
|
224
|
+
def missing_data!
|
225
|
+
raise MissingData.new(@last_query_type, @last_id, @last_annotations)
|
226
|
+
end
|
227
|
+
|
165
228
|
def to_js
|
166
229
|
{ :performQuery => proc_for(:perform_query) }
|
167
230
|
end
|
168
231
|
end
|
169
232
|
|
170
233
|
class Context
|
234
|
+
include Util
|
235
|
+
|
171
236
|
attr_reader :gibbon
|
172
237
|
def initialize(js={})
|
173
238
|
if js.is_a? Hash
|
@@ -209,43 +274,6 @@ module GoodGuide
|
|
209
274
|
[output, error]
|
210
275
|
end
|
211
276
|
|
212
|
-
def hash_to_ruby(js_hash)
|
213
|
-
return nil unless js_hash
|
214
|
-
|
215
|
-
ruby_hash = {}
|
216
|
-
iterator = lambda { |this, k, v|
|
217
|
-
ruby_hash[k] = obj_to_ruby(v)
|
218
|
-
}
|
219
|
-
|
220
|
-
js_hash[:each].methodcall js_hash, iterator
|
221
|
-
|
222
|
-
ruby_hash
|
223
|
-
end
|
224
|
-
|
225
|
-
def hash_to_js(ruby_hash)
|
226
|
-
js_hash = gibbon[:Hash].new
|
227
|
-
ruby_hash.each do |k, v|
|
228
|
-
js_hash.set(k, v)
|
229
|
-
end
|
230
|
-
js_hash
|
231
|
-
end
|
232
|
-
|
233
|
-
def obj_to_ruby(o)
|
234
|
-
case o
|
235
|
-
when V8::Array
|
236
|
-
o.map { |x| obj_to_ruby(x) }
|
237
|
-
when V8::Object
|
238
|
-
o = o.asJSON if o.respond_to? :asJSON
|
239
|
-
|
240
|
-
out = {}
|
241
|
-
o.each do |k, v|
|
242
|
-
out[k] = obj_to_ruby(v)
|
243
|
-
end
|
244
|
-
out
|
245
|
-
else
|
246
|
-
o
|
247
|
-
end
|
248
|
-
end
|
249
277
|
end
|
250
278
|
|
251
279
|
class JS < V8::Context
|
@@ -1034,7 +1034,7 @@ parse = Gibbon.parse = (function() {
|
|
1034
1034
|
lexeme = function(p) {
|
1035
1035
|
return p.skip(ignore);
|
1036
1036
|
};
|
1037
|
-
identifier = regex(/^[a-z][\w-]
|
1037
|
+
identifier = regex(/^[a-z][\w-]*[?]?/i);
|
1038
1038
|
arrow = lexeme(string('->'));
|
1039
1039
|
define = lexeme(string(':='));
|
1040
1040
|
pair = lexeme(string(':'));
|
@@ -1219,241 +1219,6 @@ parse = Gibbon.parse = (function() {
|
|
1219
1219
|
return parse;
|
1220
1220
|
})();
|
1221
1221
|
// Generated by CoffeeScript 1.6.3
|
1222
|
-
var stdlib;
|
1223
|
-
|
1224
|
-
stdlib = Gibbon.stdlib = (function() {
|
1225
|
-
return {
|
1226
|
-
"case": {
|
1227
|
-
type: parse.type('case [bool : %b] = % -> %b'),
|
1228
|
-
impl: function(_, evalList) {
|
1229
|
-
return evalList.then(function(list) {
|
1230
|
-
var out, step;
|
1231
|
-
step = function(pair, next) {
|
1232
|
-
return pair.first.then(function(cond) {
|
1233
|
-
if (cond.value) {
|
1234
|
-
return pair.second;
|
1235
|
-
} else {
|
1236
|
-
return next();
|
1237
|
-
}
|
1238
|
-
});
|
1239
|
-
};
|
1240
|
-
out = function() {
|
1241
|
-
throw new Error('Runtime Error: non-exhaustive cases');
|
1242
|
-
};
|
1243
|
-
return Promise.iter(list.elements, step, out);
|
1244
|
-
});
|
1245
|
-
}
|
1246
|
-
},
|
1247
|
-
weight: {
|
1248
|
-
type: parse.type('weight [numeric : numeric] = % -> numeric'),
|
1249
|
-
impl: function(_, eWeights) {
|
1250
|
-
return eWeights.then(function(weights) {
|
1251
|
-
return Promise.combine(weights.elements).then(function(pairs) {
|
1252
|
-
var denominator, numerator, p, process;
|
1253
|
-
numerator = 0;
|
1254
|
-
denominator = 0;
|
1255
|
-
process = function(pair) {
|
1256
|
-
return Promise.combine([pair.first, pair.second]).after(function(_arg) {
|
1257
|
-
var first, second;
|
1258
|
-
first = _arg[0], second = _arg[1];
|
1259
|
-
numerator += first.value * second.value;
|
1260
|
-
return denominator += second.value;
|
1261
|
-
});
|
1262
|
-
};
|
1263
|
-
return Promise.combine((function() {
|
1264
|
-
var _i, _len, _results;
|
1265
|
-
_results = [];
|
1266
|
-
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
1267
|
-
p = pairs[_i];
|
1268
|
-
_results.push(process(p));
|
1269
|
-
}
|
1270
|
-
return _results;
|
1271
|
-
})()).then(function() {
|
1272
|
-
if (denominator === 0) {
|
1273
|
-
return Promise.fail('cannot divide by zero');
|
1274
|
-
}
|
1275
|
-
debugger;
|
1276
|
-
return Promise.unit(Value.number(numerator / denominator));
|
1277
|
-
});
|
1278
|
-
});
|
1279
|
-
});
|
1280
|
-
}
|
1281
|
-
},
|
1282
|
-
filter: {
|
1283
|
-
type: parse.type('filter { %a -> bool } = [%a] -> [%a]'),
|
1284
|
-
impl: function(evalInput, evalBlock) {
|
1285
|
-
return evalBlock.then(function(block) {
|
1286
|
-
var fn;
|
1287
|
-
fn = block.fn;
|
1288
|
-
return evalInput.then(function(list) {
|
1289
|
-
var check, e, out;
|
1290
|
-
out = [];
|
1291
|
-
check = function(thunk) {
|
1292
|
-
return fn(thunk).after(function(bool) {
|
1293
|
-
if (bool.value) {
|
1294
|
-
return out.push(thunk);
|
1295
|
-
}
|
1296
|
-
});
|
1297
|
-
};
|
1298
|
-
return Promise.combine((function() {
|
1299
|
-
var _i, _len, _ref, _results;
|
1300
|
-
_ref = list.elements;
|
1301
|
-
_results = [];
|
1302
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1303
|
-
e = _ref[_i];
|
1304
|
-
_results.push(check(e));
|
1305
|
-
}
|
1306
|
-
return _results;
|
1307
|
-
})()).map(function() {
|
1308
|
-
return Value.list(out);
|
1309
|
-
});
|
1310
|
-
});
|
1311
|
-
});
|
1312
|
-
}
|
1313
|
-
},
|
1314
|
-
scale: {
|
1315
|
-
type: parse.type('scale (numeric:numeric) (numeric:numeric) = numeric -> numeric'),
|
1316
|
-
impl: function(eInput, eDomain, eRange) {
|
1317
|
-
return Promise.combine([eInput, eDomain, eRange]).then(function(_arg) {
|
1318
|
-
var bounds, dom, input, range;
|
1319
|
-
input = _arg[0], dom = _arg[1], range = _arg[2];
|
1320
|
-
bounds = Promise.combine([dom.first, dom.second, range.first, range.second]);
|
1321
|
-
return bounds.map(function(_arg1) {
|
1322
|
-
var domHigh, domLow, domSize, rangeHigh, rangeLow, rangeSize, retranslated, scaled, translated;
|
1323
|
-
domLow = _arg1[0], domHigh = _arg1[1], rangeLow = _arg1[2], rangeHigh = _arg1[3];
|
1324
|
-
if (input.value < domLow.value) {
|
1325
|
-
input = domLow;
|
1326
|
-
} else if (input.value > domHigh.value) {
|
1327
|
-
input = domHigh;
|
1328
|
-
}
|
1329
|
-
domSize = domHigh.value - domLow.value;
|
1330
|
-
rangeSize = rangeHigh.value - rangeLow.value;
|
1331
|
-
translated = input.value - domLow.value;
|
1332
|
-
scaled = translated * rangeSize / domSize;
|
1333
|
-
retranslated = scaled + rangeLow.value;
|
1334
|
-
return Value.number(retranslated);
|
1335
|
-
});
|
1336
|
-
});
|
1337
|
-
}
|
1338
|
-
},
|
1339
|
-
map: {
|
1340
|
-
type: parse.type('map { %a -> %b } = [%a] -> [%b]'),
|
1341
|
-
impl: function(evalList, evalBlock) {
|
1342
|
-
return evalList.then(function(list) {
|
1343
|
-
return evalBlock.map(function(block) {
|
1344
|
-
var e, fn;
|
1345
|
-
fn = block.fn;
|
1346
|
-
return Value.list((function() {
|
1347
|
-
var _i, _len, _ref, _results;
|
1348
|
-
_ref = list.elements;
|
1349
|
-
_results = [];
|
1350
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1351
|
-
e = _ref[_i];
|
1352
|
-
_results.push(fn(e));
|
1353
|
-
}
|
1354
|
-
return _results;
|
1355
|
-
})());
|
1356
|
-
});
|
1357
|
-
});
|
1358
|
-
}
|
1359
|
-
},
|
1360
|
-
count: {
|
1361
|
-
type: parse.type('count = [%a] -> numeric'),
|
1362
|
-
impl: function(evalList) {
|
1363
|
-
return evalList.map(function(list) {
|
1364
|
-
return Value.number(list.elements.length);
|
1365
|
-
});
|
1366
|
-
}
|
1367
|
-
},
|
1368
|
-
sum: {
|
1369
|
-
type: parse.type('sum = [numeric] -> numeric'),
|
1370
|
-
impl: function(list) {
|
1371
|
-
return list.then(function(val) {
|
1372
|
-
return Promise.combine(val.elements).then(function(vals) {
|
1373
|
-
var e, out, _i, _len;
|
1374
|
-
out = 0;
|
1375
|
-
for (_i = 0, _len = vals.length; _i < _len; _i++) {
|
1376
|
-
e = vals[_i];
|
1377
|
-
out += e.value;
|
1378
|
-
}
|
1379
|
-
return Promise.unit(Value.number(out));
|
1380
|
-
});
|
1381
|
-
});
|
1382
|
-
}
|
1383
|
-
},
|
1384
|
-
first: {
|
1385
|
-
type: parse.type('first = [%a] -> %a'),
|
1386
|
-
impl: function(list) {
|
1387
|
-
return list.then(function(val) {
|
1388
|
-
return val.elements[0];
|
1389
|
-
});
|
1390
|
-
}
|
1391
|
-
},
|
1392
|
-
add: {
|
1393
|
-
type: parse.type('add numeric = numeric -> numeric'),
|
1394
|
-
impl: function(input, num) {
|
1395
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1396
|
-
var lhs, rhs;
|
1397
|
-
lhs = _arg[0], rhs = _arg[1];
|
1398
|
-
return Value.number(lhs.value + rhs.value);
|
1399
|
-
});
|
1400
|
-
}
|
1401
|
-
},
|
1402
|
-
sub: {
|
1403
|
-
type: parse.type('sub numeric = numeric -> numeric'),
|
1404
|
-
impl: function(input, num) {
|
1405
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1406
|
-
var lhs, rhs;
|
1407
|
-
lhs = _arg[0], rhs = _arg[1];
|
1408
|
-
return Value.number(lhs.value - rhs.value);
|
1409
|
-
});
|
1410
|
-
}
|
1411
|
-
},
|
1412
|
-
id: {
|
1413
|
-
type: parse.type('id = %a -> %a'),
|
1414
|
-
impl: function(x) {
|
1415
|
-
return x;
|
1416
|
-
}
|
1417
|
-
},
|
1418
|
-
"else": {
|
1419
|
-
type: parse.type('else = % -> bool'),
|
1420
|
-
impl: function(_) {
|
1421
|
-
return Promise.unit(Value.boolean(true));
|
1422
|
-
}
|
1423
|
-
},
|
1424
|
-
gt: {
|
1425
|
-
type: parse.type('gt numeric = numeric -> bool'),
|
1426
|
-
impl: function(input, num) {
|
1427
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1428
|
-
var lhs, rhs;
|
1429
|
-
lhs = _arg[0], rhs = _arg[1];
|
1430
|
-
return Value.boolean(lhs.value > rhs.value);
|
1431
|
-
});
|
1432
|
-
}
|
1433
|
-
},
|
1434
|
-
lt: {
|
1435
|
-
type: parse.type('lt numeric = numeric -> bool'),
|
1436
|
-
impl: function(input, num) {
|
1437
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1438
|
-
var lhs, rhs;
|
1439
|
-
lhs = _arg[0], rhs = _arg[1];
|
1440
|
-
return Value.boolean(lhs.value < rhs.value);
|
1441
|
-
});
|
1442
|
-
}
|
1443
|
-
},
|
1444
|
-
eq: {
|
1445
|
-
type: parse.type('eq %a = %a -> bool'),
|
1446
|
-
impl: function(input, obj) {
|
1447
|
-
return Promise.combine([input, obj]).then(function(_arg) {
|
1448
|
-
var lhs, rhs;
|
1449
|
-
lhs = _arg[0], rhs = _arg[1];
|
1450
|
-
return lhs.equals(rhs);
|
1451
|
-
});
|
1452
|
-
}
|
1453
|
-
}
|
1454
|
-
};
|
1455
|
-
})();
|
1456
|
-
// Generated by CoffeeScript 1.6.3
|
1457
1222
|
var Semantic, Type, TypeLookup, analyze, _ref, _ref1, _ref2,
|
1458
1223
|
__hasProp = {}.hasOwnProperty,
|
1459
1224
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
@@ -2874,6 +2639,317 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2874
2639
|
};
|
2875
2640
|
})();
|
2876
2641
|
// Generated by CoffeeScript 1.6.3
|
2642
|
+
var stdlib;
|
2643
|
+
|
2644
|
+
stdlib = Gibbon.stdlib = (function() {
|
2645
|
+
var combine, iter, unit, vFalse, vTrue;
|
2646
|
+
unit = Promise.unit;
|
2647
|
+
iter = Promise.iter;
|
2648
|
+
combine = Promise.combine;
|
2649
|
+
vTrue = Value.boolean(true);
|
2650
|
+
vFalse = Value.boolean(false);
|
2651
|
+
return {
|
2652
|
+
"case": {
|
2653
|
+
type: parse.type('case [bool : %b] = % -> %b'),
|
2654
|
+
impl: function(_, evalList) {
|
2655
|
+
return evalList.then(function(list) {
|
2656
|
+
var out, step;
|
2657
|
+
step = function(pair, next) {
|
2658
|
+
return pair.first.then(function(cond) {
|
2659
|
+
if (cond.value) {
|
2660
|
+
return pair.second;
|
2661
|
+
} else {
|
2662
|
+
return next();
|
2663
|
+
}
|
2664
|
+
});
|
2665
|
+
};
|
2666
|
+
out = function() {
|
2667
|
+
throw new Error('Runtime Error: non-exhaustive cases');
|
2668
|
+
};
|
2669
|
+
return iter(list.elements, step, out);
|
2670
|
+
});
|
2671
|
+
}
|
2672
|
+
},
|
2673
|
+
"any?": {
|
2674
|
+
type: parse.type('any? { %a -> bool } = [%a] -> bool'),
|
2675
|
+
impl: function(evalList, evalBlock) {
|
2676
|
+
return combine([evalList, evalBlock]).then(function(_arg) {
|
2677
|
+
var block, booleans, e, fn, list, out, step;
|
2678
|
+
list = _arg[0], block = _arg[1];
|
2679
|
+
fn = block.fn;
|
2680
|
+
booleans = (function() {
|
2681
|
+
var _i, _len, _ref, _results;
|
2682
|
+
_ref = list.elements;
|
2683
|
+
_results = [];
|
2684
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2685
|
+
e = _ref[_i];
|
2686
|
+
_results.push(fn(e));
|
2687
|
+
}
|
2688
|
+
return _results;
|
2689
|
+
})();
|
2690
|
+
step = function(cond, next) {
|
2691
|
+
if (cond.value) {
|
2692
|
+
return unit(vTrue);
|
2693
|
+
} else {
|
2694
|
+
return next();
|
2695
|
+
}
|
2696
|
+
};
|
2697
|
+
out = function() {
|
2698
|
+
return unit(vFalse);
|
2699
|
+
};
|
2700
|
+
return iter(booleans, step, out);
|
2701
|
+
});
|
2702
|
+
}
|
2703
|
+
},
|
2704
|
+
"all?": {
|
2705
|
+
type: parse.type('all? { %a -> bool } = [%a] -> bool'),
|
2706
|
+
impl: function(evalList, evalBlock) {
|
2707
|
+
return combine([evalList, evalBlock]).then(function(_arg) {
|
2708
|
+
var block, booleans, e, fn, list, out, step;
|
2709
|
+
list = _arg[0], block = _arg[1];
|
2710
|
+
fn = block.fn;
|
2711
|
+
booleans = (function() {
|
2712
|
+
var _i, _len, _ref, _results;
|
2713
|
+
_ref = list.elements;
|
2714
|
+
_results = [];
|
2715
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2716
|
+
e = _ref[_i];
|
2717
|
+
_results.push(fn(e));
|
2718
|
+
}
|
2719
|
+
return _results;
|
2720
|
+
})();
|
2721
|
+
step = function(cond, next) {
|
2722
|
+
if (cond.value) {
|
2723
|
+
return next();
|
2724
|
+
} else {
|
2725
|
+
return unit(vFalse);
|
2726
|
+
}
|
2727
|
+
};
|
2728
|
+
out = function() {
|
2729
|
+
return trueP;
|
2730
|
+
};
|
2731
|
+
return Promise.iter(booleans, step, out);
|
2732
|
+
});
|
2733
|
+
}
|
2734
|
+
},
|
2735
|
+
"empty?": {
|
2736
|
+
type: parse.type('empty? = [%] -> bool'),
|
2737
|
+
impl: function(evalList) {
|
2738
|
+
return evalList.map(function(list) {
|
2739
|
+
return Value.boolean(list.length === 0);
|
2740
|
+
});
|
2741
|
+
}
|
2742
|
+
},
|
2743
|
+
weight: {
|
2744
|
+
type: parse.type('weight [numeric : numeric] = % -> numeric'),
|
2745
|
+
impl: function(_, eWeights) {
|
2746
|
+
return eWeights.then(function(weights) {
|
2747
|
+
return combine(weights.elements).then(function(pairs) {
|
2748
|
+
var denominator, numerator, p, process;
|
2749
|
+
numerator = 0;
|
2750
|
+
denominator = 0;
|
2751
|
+
process = function(pair) {
|
2752
|
+
return combine([pair.first, pair.second]).after(function(_arg) {
|
2753
|
+
var first, second;
|
2754
|
+
first = _arg[0], second = _arg[1];
|
2755
|
+
numerator += first.value * second.value;
|
2756
|
+
return denominator += second.value;
|
2757
|
+
});
|
2758
|
+
};
|
2759
|
+
return combine((function() {
|
2760
|
+
var _i, _len, _results;
|
2761
|
+
_results = [];
|
2762
|
+
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
2763
|
+
p = pairs[_i];
|
2764
|
+
_results.push(process(p));
|
2765
|
+
}
|
2766
|
+
return _results;
|
2767
|
+
})()).then(function() {
|
2768
|
+
if (denominator === 0) {
|
2769
|
+
return Promise.fail('cannot divide by zero');
|
2770
|
+
}
|
2771
|
+
debugger;
|
2772
|
+
return Promise.unit(Value.number(numerator / denominator));
|
2773
|
+
});
|
2774
|
+
});
|
2775
|
+
});
|
2776
|
+
}
|
2777
|
+
},
|
2778
|
+
filter: {
|
2779
|
+
type: parse.type('filter { %a -> bool } = [%a] -> [%a]'),
|
2780
|
+
impl: function(evalInput, evalBlock) {
|
2781
|
+
return evalBlock.then(function(block) {
|
2782
|
+
var fn;
|
2783
|
+
fn = block.fn;
|
2784
|
+
return evalInput.then(function(list) {
|
2785
|
+
var check, e, out;
|
2786
|
+
out = [];
|
2787
|
+
check = function(thunk) {
|
2788
|
+
return fn(thunk).after(function(bool) {
|
2789
|
+
if (bool.value) {
|
2790
|
+
return out.push(thunk);
|
2791
|
+
}
|
2792
|
+
});
|
2793
|
+
};
|
2794
|
+
return combine((function() {
|
2795
|
+
var _i, _len, _ref, _results;
|
2796
|
+
_ref = list.elements;
|
2797
|
+
_results = [];
|
2798
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2799
|
+
e = _ref[_i];
|
2800
|
+
_results.push(check(e));
|
2801
|
+
}
|
2802
|
+
return _results;
|
2803
|
+
})()).map(function() {
|
2804
|
+
return Value.list(out);
|
2805
|
+
});
|
2806
|
+
});
|
2807
|
+
});
|
2808
|
+
}
|
2809
|
+
},
|
2810
|
+
scale: {
|
2811
|
+
type: parse.type('scale (numeric:numeric) (numeric:numeric) = numeric -> numeric'),
|
2812
|
+
impl: function(eInput, eDomain, eRange) {
|
2813
|
+
return combine([eInput, eDomain, eRange]).then(function(_arg) {
|
2814
|
+
var bounds, dom, input, range;
|
2815
|
+
input = _arg[0], dom = _arg[1], range = _arg[2];
|
2816
|
+
bounds = combine([dom.first, dom.second, range.first, range.second]);
|
2817
|
+
return bounds.map(function(_arg1) {
|
2818
|
+
var domHigh, domLow, domSize, rangeHigh, rangeLow, rangeSize, retranslated, scaled, translated;
|
2819
|
+
domLow = _arg1[0], domHigh = _arg1[1], rangeLow = _arg1[2], rangeHigh = _arg1[3];
|
2820
|
+
if (input.value < domLow.value) {
|
2821
|
+
input = domLow;
|
2822
|
+
} else if (input.value > domHigh.value) {
|
2823
|
+
input = domHigh;
|
2824
|
+
}
|
2825
|
+
domSize = domHigh.value - domLow.value;
|
2826
|
+
rangeSize = rangeHigh.value - rangeLow.value;
|
2827
|
+
translated = input.value - domLow.value;
|
2828
|
+
scaled = translated * rangeSize / domSize;
|
2829
|
+
retranslated = scaled + rangeLow.value;
|
2830
|
+
return Value.number(retranslated);
|
2831
|
+
});
|
2832
|
+
});
|
2833
|
+
}
|
2834
|
+
},
|
2835
|
+
map: {
|
2836
|
+
type: parse.type('map { %a -> %b } = [%a] -> [%b]'),
|
2837
|
+
impl: function(evalList, evalBlock) {
|
2838
|
+
return evalList.then(function(list) {
|
2839
|
+
return evalBlock.map(function(block) {
|
2840
|
+
var e, fn;
|
2841
|
+
fn = block.fn;
|
2842
|
+
return Value.list((function() {
|
2843
|
+
var _i, _len, _ref, _results;
|
2844
|
+
_ref = list.elements;
|
2845
|
+
_results = [];
|
2846
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2847
|
+
e = _ref[_i];
|
2848
|
+
_results.push(fn(e));
|
2849
|
+
}
|
2850
|
+
return _results;
|
2851
|
+
})());
|
2852
|
+
});
|
2853
|
+
});
|
2854
|
+
}
|
2855
|
+
},
|
2856
|
+
count: {
|
2857
|
+
type: parse.type('count = [%a] -> numeric'),
|
2858
|
+
impl: function(evalList) {
|
2859
|
+
return evalList.map(function(list) {
|
2860
|
+
return Value.number(list.elements.length);
|
2861
|
+
});
|
2862
|
+
}
|
2863
|
+
},
|
2864
|
+
sum: {
|
2865
|
+
type: parse.type('sum = [numeric] -> numeric'),
|
2866
|
+
impl: function(list) {
|
2867
|
+
return list.then(function(val) {
|
2868
|
+
return combine(val.elements).then(function(vals) {
|
2869
|
+
var e, out, _i, _len;
|
2870
|
+
out = 0;
|
2871
|
+
for (_i = 0, _len = vals.length; _i < _len; _i++) {
|
2872
|
+
e = vals[_i];
|
2873
|
+
out += e.value;
|
2874
|
+
}
|
2875
|
+
return Promise.unit(Value.number(out));
|
2876
|
+
});
|
2877
|
+
});
|
2878
|
+
}
|
2879
|
+
},
|
2880
|
+
first: {
|
2881
|
+
type: parse.type('first = [%a] -> %a'),
|
2882
|
+
impl: function(list) {
|
2883
|
+
return list.then(function(val) {
|
2884
|
+
return val.elements[0];
|
2885
|
+
});
|
2886
|
+
}
|
2887
|
+
},
|
2888
|
+
add: {
|
2889
|
+
type: parse.type('add numeric = numeric -> numeric'),
|
2890
|
+
impl: function(input, num) {
|
2891
|
+
return combine([input, num]).map(function(_arg) {
|
2892
|
+
var lhs, rhs;
|
2893
|
+
lhs = _arg[0], rhs = _arg[1];
|
2894
|
+
return Value.number(lhs.value + rhs.value);
|
2895
|
+
});
|
2896
|
+
}
|
2897
|
+
},
|
2898
|
+
sub: {
|
2899
|
+
type: parse.type('sub numeric = numeric -> numeric'),
|
2900
|
+
impl: function(input, num) {
|
2901
|
+
return combine([input, num]).map(function(_arg) {
|
2902
|
+
var lhs, rhs;
|
2903
|
+
lhs = _arg[0], rhs = _arg[1];
|
2904
|
+
return Value.number(lhs.value - rhs.value);
|
2905
|
+
});
|
2906
|
+
}
|
2907
|
+
},
|
2908
|
+
id: {
|
2909
|
+
type: parse.type('id = %a -> %a'),
|
2910
|
+
impl: function(x) {
|
2911
|
+
return x;
|
2912
|
+
}
|
2913
|
+
},
|
2914
|
+
"else": {
|
2915
|
+
type: parse.type('else = % -> bool'),
|
2916
|
+
impl: function(_) {
|
2917
|
+
return unit(vTrue);
|
2918
|
+
}
|
2919
|
+
},
|
2920
|
+
gt: {
|
2921
|
+
type: parse.type('gt numeric = numeric -> bool'),
|
2922
|
+
impl: function(input, num) {
|
2923
|
+
return combine([input, num]).map(function(_arg) {
|
2924
|
+
var lhs, rhs;
|
2925
|
+
lhs = _arg[0], rhs = _arg[1];
|
2926
|
+
return Value.boolean(lhs.value > rhs.value);
|
2927
|
+
});
|
2928
|
+
}
|
2929
|
+
},
|
2930
|
+
lt: {
|
2931
|
+
type: parse.type('lt numeric = numeric -> bool'),
|
2932
|
+
impl: function(input, num) {
|
2933
|
+
return combine([input, num]).map(function(_arg) {
|
2934
|
+
var lhs, rhs;
|
2935
|
+
lhs = _arg[0], rhs = _arg[1];
|
2936
|
+
return Value.boolean(lhs.value < rhs.value);
|
2937
|
+
});
|
2938
|
+
}
|
2939
|
+
},
|
2940
|
+
eq: {
|
2941
|
+
type: parse.type('eq %a = %a -> bool'),
|
2942
|
+
impl: function(input, obj) {
|
2943
|
+
return combine([input, obj]).then(function(_arg) {
|
2944
|
+
var lhs, rhs;
|
2945
|
+
lhs = _arg[0], rhs = _arg[1];
|
2946
|
+
return lhs.equals(rhs);
|
2947
|
+
});
|
2948
|
+
}
|
2949
|
+
}
|
2950
|
+
};
|
2951
|
+
})();
|
2952
|
+
// Generated by CoffeeScript 1.6.3
|
2877
2953
|
Gibbon.jsonConsumer = (function() {
|
2878
2954
|
return function(tables) {
|
2879
2955
|
var analyzeList, getType, getValue, lists;
|
@@ -1028,7 +1028,7 @@ parse = Gibbon.parse = (function() {
|
|
1028
1028
|
lexeme = function(p) {
|
1029
1029
|
return p.skip(ignore);
|
1030
1030
|
};
|
1031
|
-
identifier = regex(/^[a-z][\w-]
|
1031
|
+
identifier = regex(/^[a-z][\w-]*[?]?/i);
|
1032
1032
|
arrow = lexeme(string('->'));
|
1033
1033
|
define = lexeme(string(':='));
|
1034
1034
|
pair = lexeme(string(':'));
|
@@ -1213,241 +1213,6 @@ parse = Gibbon.parse = (function() {
|
|
1213
1213
|
return parse;
|
1214
1214
|
})();
|
1215
1215
|
// Generated by CoffeeScript 1.6.3
|
1216
|
-
var stdlib;
|
1217
|
-
|
1218
|
-
stdlib = Gibbon.stdlib = (function() {
|
1219
|
-
return {
|
1220
|
-
"case": {
|
1221
|
-
type: parse.type('case [bool : %b] = % -> %b'),
|
1222
|
-
impl: function(_, evalList) {
|
1223
|
-
return evalList.then(function(list) {
|
1224
|
-
var out, step;
|
1225
|
-
step = function(pair, next) {
|
1226
|
-
return pair.first.then(function(cond) {
|
1227
|
-
if (cond.value) {
|
1228
|
-
return pair.second;
|
1229
|
-
} else {
|
1230
|
-
return next();
|
1231
|
-
}
|
1232
|
-
});
|
1233
|
-
};
|
1234
|
-
out = function() {
|
1235
|
-
throw new Error('Runtime Error: non-exhaustive cases');
|
1236
|
-
};
|
1237
|
-
return Promise.iter(list.elements, step, out);
|
1238
|
-
});
|
1239
|
-
}
|
1240
|
-
},
|
1241
|
-
weight: {
|
1242
|
-
type: parse.type('weight [numeric : numeric] = % -> numeric'),
|
1243
|
-
impl: function(_, eWeights) {
|
1244
|
-
return eWeights.then(function(weights) {
|
1245
|
-
return Promise.combine(weights.elements).then(function(pairs) {
|
1246
|
-
var denominator, numerator, p, process;
|
1247
|
-
numerator = 0;
|
1248
|
-
denominator = 0;
|
1249
|
-
process = function(pair) {
|
1250
|
-
return Promise.combine([pair.first, pair.second]).after(function(_arg) {
|
1251
|
-
var first, second;
|
1252
|
-
first = _arg[0], second = _arg[1];
|
1253
|
-
numerator += first.value * second.value;
|
1254
|
-
return denominator += second.value;
|
1255
|
-
});
|
1256
|
-
};
|
1257
|
-
return Promise.combine((function() {
|
1258
|
-
var _i, _len, _results;
|
1259
|
-
_results = [];
|
1260
|
-
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
1261
|
-
p = pairs[_i];
|
1262
|
-
_results.push(process(p));
|
1263
|
-
}
|
1264
|
-
return _results;
|
1265
|
-
})()).then(function() {
|
1266
|
-
if (denominator === 0) {
|
1267
|
-
return Promise.fail('cannot divide by zero');
|
1268
|
-
}
|
1269
|
-
debugger;
|
1270
|
-
return Promise.unit(Value.number(numerator / denominator));
|
1271
|
-
});
|
1272
|
-
});
|
1273
|
-
});
|
1274
|
-
}
|
1275
|
-
},
|
1276
|
-
filter: {
|
1277
|
-
type: parse.type('filter { %a -> bool } = [%a] -> [%a]'),
|
1278
|
-
impl: function(evalInput, evalBlock) {
|
1279
|
-
return evalBlock.then(function(block) {
|
1280
|
-
var fn;
|
1281
|
-
fn = block.fn;
|
1282
|
-
return evalInput.then(function(list) {
|
1283
|
-
var check, e, out;
|
1284
|
-
out = [];
|
1285
|
-
check = function(thunk) {
|
1286
|
-
return fn(thunk).after(function(bool) {
|
1287
|
-
if (bool.value) {
|
1288
|
-
return out.push(thunk);
|
1289
|
-
}
|
1290
|
-
});
|
1291
|
-
};
|
1292
|
-
return Promise.combine((function() {
|
1293
|
-
var _i, _len, _ref, _results;
|
1294
|
-
_ref = list.elements;
|
1295
|
-
_results = [];
|
1296
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1297
|
-
e = _ref[_i];
|
1298
|
-
_results.push(check(e));
|
1299
|
-
}
|
1300
|
-
return _results;
|
1301
|
-
})()).map(function() {
|
1302
|
-
return Value.list(out);
|
1303
|
-
});
|
1304
|
-
});
|
1305
|
-
});
|
1306
|
-
}
|
1307
|
-
},
|
1308
|
-
scale: {
|
1309
|
-
type: parse.type('scale (numeric:numeric) (numeric:numeric) = numeric -> numeric'),
|
1310
|
-
impl: function(eInput, eDomain, eRange) {
|
1311
|
-
return Promise.combine([eInput, eDomain, eRange]).then(function(_arg) {
|
1312
|
-
var bounds, dom, input, range;
|
1313
|
-
input = _arg[0], dom = _arg[1], range = _arg[2];
|
1314
|
-
bounds = Promise.combine([dom.first, dom.second, range.first, range.second]);
|
1315
|
-
return bounds.map(function(_arg1) {
|
1316
|
-
var domHigh, domLow, domSize, rangeHigh, rangeLow, rangeSize, retranslated, scaled, translated;
|
1317
|
-
domLow = _arg1[0], domHigh = _arg1[1], rangeLow = _arg1[2], rangeHigh = _arg1[3];
|
1318
|
-
if (input.value < domLow.value) {
|
1319
|
-
input = domLow;
|
1320
|
-
} else if (input.value > domHigh.value) {
|
1321
|
-
input = domHigh;
|
1322
|
-
}
|
1323
|
-
domSize = domHigh.value - domLow.value;
|
1324
|
-
rangeSize = rangeHigh.value - rangeLow.value;
|
1325
|
-
translated = input.value - domLow.value;
|
1326
|
-
scaled = translated * rangeSize / domSize;
|
1327
|
-
retranslated = scaled + rangeLow.value;
|
1328
|
-
return Value.number(retranslated);
|
1329
|
-
});
|
1330
|
-
});
|
1331
|
-
}
|
1332
|
-
},
|
1333
|
-
map: {
|
1334
|
-
type: parse.type('map { %a -> %b } = [%a] -> [%b]'),
|
1335
|
-
impl: function(evalList, evalBlock) {
|
1336
|
-
return evalList.then(function(list) {
|
1337
|
-
return evalBlock.map(function(block) {
|
1338
|
-
var e, fn;
|
1339
|
-
fn = block.fn;
|
1340
|
-
return Value.list((function() {
|
1341
|
-
var _i, _len, _ref, _results;
|
1342
|
-
_ref = list.elements;
|
1343
|
-
_results = [];
|
1344
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1345
|
-
e = _ref[_i];
|
1346
|
-
_results.push(fn(e));
|
1347
|
-
}
|
1348
|
-
return _results;
|
1349
|
-
})());
|
1350
|
-
});
|
1351
|
-
});
|
1352
|
-
}
|
1353
|
-
},
|
1354
|
-
count: {
|
1355
|
-
type: parse.type('count = [%a] -> numeric'),
|
1356
|
-
impl: function(evalList) {
|
1357
|
-
return evalList.map(function(list) {
|
1358
|
-
return Value.number(list.elements.length);
|
1359
|
-
});
|
1360
|
-
}
|
1361
|
-
},
|
1362
|
-
sum: {
|
1363
|
-
type: parse.type('sum = [numeric] -> numeric'),
|
1364
|
-
impl: function(list) {
|
1365
|
-
return list.then(function(val) {
|
1366
|
-
return Promise.combine(val.elements).then(function(vals) {
|
1367
|
-
var e, out, _i, _len;
|
1368
|
-
out = 0;
|
1369
|
-
for (_i = 0, _len = vals.length; _i < _len; _i++) {
|
1370
|
-
e = vals[_i];
|
1371
|
-
out += e.value;
|
1372
|
-
}
|
1373
|
-
return Promise.unit(Value.number(out));
|
1374
|
-
});
|
1375
|
-
});
|
1376
|
-
}
|
1377
|
-
},
|
1378
|
-
first: {
|
1379
|
-
type: parse.type('first = [%a] -> %a'),
|
1380
|
-
impl: function(list) {
|
1381
|
-
return list.then(function(val) {
|
1382
|
-
return val.elements[0];
|
1383
|
-
});
|
1384
|
-
}
|
1385
|
-
},
|
1386
|
-
add: {
|
1387
|
-
type: parse.type('add numeric = numeric -> numeric'),
|
1388
|
-
impl: function(input, num) {
|
1389
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1390
|
-
var lhs, rhs;
|
1391
|
-
lhs = _arg[0], rhs = _arg[1];
|
1392
|
-
return Value.number(lhs.value + rhs.value);
|
1393
|
-
});
|
1394
|
-
}
|
1395
|
-
},
|
1396
|
-
sub: {
|
1397
|
-
type: parse.type('sub numeric = numeric -> numeric'),
|
1398
|
-
impl: function(input, num) {
|
1399
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1400
|
-
var lhs, rhs;
|
1401
|
-
lhs = _arg[0], rhs = _arg[1];
|
1402
|
-
return Value.number(lhs.value - rhs.value);
|
1403
|
-
});
|
1404
|
-
}
|
1405
|
-
},
|
1406
|
-
id: {
|
1407
|
-
type: parse.type('id = %a -> %a'),
|
1408
|
-
impl: function(x) {
|
1409
|
-
return x;
|
1410
|
-
}
|
1411
|
-
},
|
1412
|
-
"else": {
|
1413
|
-
type: parse.type('else = % -> bool'),
|
1414
|
-
impl: function(_) {
|
1415
|
-
return Promise.unit(Value.boolean(true));
|
1416
|
-
}
|
1417
|
-
},
|
1418
|
-
gt: {
|
1419
|
-
type: parse.type('gt numeric = numeric -> bool'),
|
1420
|
-
impl: function(input, num) {
|
1421
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1422
|
-
var lhs, rhs;
|
1423
|
-
lhs = _arg[0], rhs = _arg[1];
|
1424
|
-
return Value.boolean(lhs.value > rhs.value);
|
1425
|
-
});
|
1426
|
-
}
|
1427
|
-
},
|
1428
|
-
lt: {
|
1429
|
-
type: parse.type('lt numeric = numeric -> bool'),
|
1430
|
-
impl: function(input, num) {
|
1431
|
-
return Promise.combine([input, num]).map(function(_arg) {
|
1432
|
-
var lhs, rhs;
|
1433
|
-
lhs = _arg[0], rhs = _arg[1];
|
1434
|
-
return Value.boolean(lhs.value < rhs.value);
|
1435
|
-
});
|
1436
|
-
}
|
1437
|
-
},
|
1438
|
-
eq: {
|
1439
|
-
type: parse.type('eq %a = %a -> bool'),
|
1440
|
-
impl: function(input, obj) {
|
1441
|
-
return Promise.combine([input, obj]).then(function(_arg) {
|
1442
|
-
var lhs, rhs;
|
1443
|
-
lhs = _arg[0], rhs = _arg[1];
|
1444
|
-
return lhs.equals(rhs);
|
1445
|
-
});
|
1446
|
-
}
|
1447
|
-
}
|
1448
|
-
};
|
1449
|
-
})();
|
1450
|
-
// Generated by CoffeeScript 1.6.3
|
1451
1216
|
var Semantic, Type, TypeLookup, analyze, _ref, _ref1, _ref2,
|
1452
1217
|
__hasProp = {}.hasOwnProperty,
|
1453
1218
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
@@ -2846,6 +2611,317 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2846
2611
|
};
|
2847
2612
|
})();
|
2848
2613
|
// Generated by CoffeeScript 1.6.3
|
2614
|
+
var stdlib;
|
2615
|
+
|
2616
|
+
stdlib = Gibbon.stdlib = (function() {
|
2617
|
+
var combine, iter, unit, vFalse, vTrue;
|
2618
|
+
unit = Promise.unit;
|
2619
|
+
iter = Promise.iter;
|
2620
|
+
combine = Promise.combine;
|
2621
|
+
vTrue = Value.boolean(true);
|
2622
|
+
vFalse = Value.boolean(false);
|
2623
|
+
return {
|
2624
|
+
"case": {
|
2625
|
+
type: parse.type('case [bool : %b] = % -> %b'),
|
2626
|
+
impl: function(_, evalList) {
|
2627
|
+
return evalList.then(function(list) {
|
2628
|
+
var out, step;
|
2629
|
+
step = function(pair, next) {
|
2630
|
+
return pair.first.then(function(cond) {
|
2631
|
+
if (cond.value) {
|
2632
|
+
return pair.second;
|
2633
|
+
} else {
|
2634
|
+
return next();
|
2635
|
+
}
|
2636
|
+
});
|
2637
|
+
};
|
2638
|
+
out = function() {
|
2639
|
+
throw new Error('Runtime Error: non-exhaustive cases');
|
2640
|
+
};
|
2641
|
+
return iter(list.elements, step, out);
|
2642
|
+
});
|
2643
|
+
}
|
2644
|
+
},
|
2645
|
+
"any?": {
|
2646
|
+
type: parse.type('any? { %a -> bool } = [%a] -> bool'),
|
2647
|
+
impl: function(evalList, evalBlock) {
|
2648
|
+
return combine([evalList, evalBlock]).then(function(_arg) {
|
2649
|
+
var block, booleans, e, fn, list, out, step;
|
2650
|
+
list = _arg[0], block = _arg[1];
|
2651
|
+
fn = block.fn;
|
2652
|
+
booleans = (function() {
|
2653
|
+
var _i, _len, _ref, _results;
|
2654
|
+
_ref = list.elements;
|
2655
|
+
_results = [];
|
2656
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2657
|
+
e = _ref[_i];
|
2658
|
+
_results.push(fn(e));
|
2659
|
+
}
|
2660
|
+
return _results;
|
2661
|
+
})();
|
2662
|
+
step = function(cond, next) {
|
2663
|
+
if (cond.value) {
|
2664
|
+
return unit(vTrue);
|
2665
|
+
} else {
|
2666
|
+
return next();
|
2667
|
+
}
|
2668
|
+
};
|
2669
|
+
out = function() {
|
2670
|
+
return unit(vFalse);
|
2671
|
+
};
|
2672
|
+
return iter(booleans, step, out);
|
2673
|
+
});
|
2674
|
+
}
|
2675
|
+
},
|
2676
|
+
"all?": {
|
2677
|
+
type: parse.type('all? { %a -> bool } = [%a] -> bool'),
|
2678
|
+
impl: function(evalList, evalBlock) {
|
2679
|
+
return combine([evalList, evalBlock]).then(function(_arg) {
|
2680
|
+
var block, booleans, e, fn, list, out, step;
|
2681
|
+
list = _arg[0], block = _arg[1];
|
2682
|
+
fn = block.fn;
|
2683
|
+
booleans = (function() {
|
2684
|
+
var _i, _len, _ref, _results;
|
2685
|
+
_ref = list.elements;
|
2686
|
+
_results = [];
|
2687
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2688
|
+
e = _ref[_i];
|
2689
|
+
_results.push(fn(e));
|
2690
|
+
}
|
2691
|
+
return _results;
|
2692
|
+
})();
|
2693
|
+
step = function(cond, next) {
|
2694
|
+
if (cond.value) {
|
2695
|
+
return next();
|
2696
|
+
} else {
|
2697
|
+
return unit(vFalse);
|
2698
|
+
}
|
2699
|
+
};
|
2700
|
+
out = function() {
|
2701
|
+
return trueP;
|
2702
|
+
};
|
2703
|
+
return Promise.iter(booleans, step, out);
|
2704
|
+
});
|
2705
|
+
}
|
2706
|
+
},
|
2707
|
+
"empty?": {
|
2708
|
+
type: parse.type('empty? = [%] -> bool'),
|
2709
|
+
impl: function(evalList) {
|
2710
|
+
return evalList.map(function(list) {
|
2711
|
+
return Value.boolean(list.length === 0);
|
2712
|
+
});
|
2713
|
+
}
|
2714
|
+
},
|
2715
|
+
weight: {
|
2716
|
+
type: parse.type('weight [numeric : numeric] = % -> numeric'),
|
2717
|
+
impl: function(_, eWeights) {
|
2718
|
+
return eWeights.then(function(weights) {
|
2719
|
+
return combine(weights.elements).then(function(pairs) {
|
2720
|
+
var denominator, numerator, p, process;
|
2721
|
+
numerator = 0;
|
2722
|
+
denominator = 0;
|
2723
|
+
process = function(pair) {
|
2724
|
+
return combine([pair.first, pair.second]).after(function(_arg) {
|
2725
|
+
var first, second;
|
2726
|
+
first = _arg[0], second = _arg[1];
|
2727
|
+
numerator += first.value * second.value;
|
2728
|
+
return denominator += second.value;
|
2729
|
+
});
|
2730
|
+
};
|
2731
|
+
return combine((function() {
|
2732
|
+
var _i, _len, _results;
|
2733
|
+
_results = [];
|
2734
|
+
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
2735
|
+
p = pairs[_i];
|
2736
|
+
_results.push(process(p));
|
2737
|
+
}
|
2738
|
+
return _results;
|
2739
|
+
})()).then(function() {
|
2740
|
+
if (denominator === 0) {
|
2741
|
+
return Promise.fail('cannot divide by zero');
|
2742
|
+
}
|
2743
|
+
debugger;
|
2744
|
+
return Promise.unit(Value.number(numerator / denominator));
|
2745
|
+
});
|
2746
|
+
});
|
2747
|
+
});
|
2748
|
+
}
|
2749
|
+
},
|
2750
|
+
filter: {
|
2751
|
+
type: parse.type('filter { %a -> bool } = [%a] -> [%a]'),
|
2752
|
+
impl: function(evalInput, evalBlock) {
|
2753
|
+
return evalBlock.then(function(block) {
|
2754
|
+
var fn;
|
2755
|
+
fn = block.fn;
|
2756
|
+
return evalInput.then(function(list) {
|
2757
|
+
var check, e, out;
|
2758
|
+
out = [];
|
2759
|
+
check = function(thunk) {
|
2760
|
+
return fn(thunk).after(function(bool) {
|
2761
|
+
if (bool.value) {
|
2762
|
+
return out.push(thunk);
|
2763
|
+
}
|
2764
|
+
});
|
2765
|
+
};
|
2766
|
+
return combine((function() {
|
2767
|
+
var _i, _len, _ref, _results;
|
2768
|
+
_ref = list.elements;
|
2769
|
+
_results = [];
|
2770
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2771
|
+
e = _ref[_i];
|
2772
|
+
_results.push(check(e));
|
2773
|
+
}
|
2774
|
+
return _results;
|
2775
|
+
})()).map(function() {
|
2776
|
+
return Value.list(out);
|
2777
|
+
});
|
2778
|
+
});
|
2779
|
+
});
|
2780
|
+
}
|
2781
|
+
},
|
2782
|
+
scale: {
|
2783
|
+
type: parse.type('scale (numeric:numeric) (numeric:numeric) = numeric -> numeric'),
|
2784
|
+
impl: function(eInput, eDomain, eRange) {
|
2785
|
+
return combine([eInput, eDomain, eRange]).then(function(_arg) {
|
2786
|
+
var bounds, dom, input, range;
|
2787
|
+
input = _arg[0], dom = _arg[1], range = _arg[2];
|
2788
|
+
bounds = combine([dom.first, dom.second, range.first, range.second]);
|
2789
|
+
return bounds.map(function(_arg1) {
|
2790
|
+
var domHigh, domLow, domSize, rangeHigh, rangeLow, rangeSize, retranslated, scaled, translated;
|
2791
|
+
domLow = _arg1[0], domHigh = _arg1[1], rangeLow = _arg1[2], rangeHigh = _arg1[3];
|
2792
|
+
if (input.value < domLow.value) {
|
2793
|
+
input = domLow;
|
2794
|
+
} else if (input.value > domHigh.value) {
|
2795
|
+
input = domHigh;
|
2796
|
+
}
|
2797
|
+
domSize = domHigh.value - domLow.value;
|
2798
|
+
rangeSize = rangeHigh.value - rangeLow.value;
|
2799
|
+
translated = input.value - domLow.value;
|
2800
|
+
scaled = translated * rangeSize / domSize;
|
2801
|
+
retranslated = scaled + rangeLow.value;
|
2802
|
+
return Value.number(retranslated);
|
2803
|
+
});
|
2804
|
+
});
|
2805
|
+
}
|
2806
|
+
},
|
2807
|
+
map: {
|
2808
|
+
type: parse.type('map { %a -> %b } = [%a] -> [%b]'),
|
2809
|
+
impl: function(evalList, evalBlock) {
|
2810
|
+
return evalList.then(function(list) {
|
2811
|
+
return evalBlock.map(function(block) {
|
2812
|
+
var e, fn;
|
2813
|
+
fn = block.fn;
|
2814
|
+
return Value.list((function() {
|
2815
|
+
var _i, _len, _ref, _results;
|
2816
|
+
_ref = list.elements;
|
2817
|
+
_results = [];
|
2818
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2819
|
+
e = _ref[_i];
|
2820
|
+
_results.push(fn(e));
|
2821
|
+
}
|
2822
|
+
return _results;
|
2823
|
+
})());
|
2824
|
+
});
|
2825
|
+
});
|
2826
|
+
}
|
2827
|
+
},
|
2828
|
+
count: {
|
2829
|
+
type: parse.type('count = [%a] -> numeric'),
|
2830
|
+
impl: function(evalList) {
|
2831
|
+
return evalList.map(function(list) {
|
2832
|
+
return Value.number(list.elements.length);
|
2833
|
+
});
|
2834
|
+
}
|
2835
|
+
},
|
2836
|
+
sum: {
|
2837
|
+
type: parse.type('sum = [numeric] -> numeric'),
|
2838
|
+
impl: function(list) {
|
2839
|
+
return list.then(function(val) {
|
2840
|
+
return combine(val.elements).then(function(vals) {
|
2841
|
+
var e, out, _i, _len;
|
2842
|
+
out = 0;
|
2843
|
+
for (_i = 0, _len = vals.length; _i < _len; _i++) {
|
2844
|
+
e = vals[_i];
|
2845
|
+
out += e.value;
|
2846
|
+
}
|
2847
|
+
return Promise.unit(Value.number(out));
|
2848
|
+
});
|
2849
|
+
});
|
2850
|
+
}
|
2851
|
+
},
|
2852
|
+
first: {
|
2853
|
+
type: parse.type('first = [%a] -> %a'),
|
2854
|
+
impl: function(list) {
|
2855
|
+
return list.then(function(val) {
|
2856
|
+
return val.elements[0];
|
2857
|
+
});
|
2858
|
+
}
|
2859
|
+
},
|
2860
|
+
add: {
|
2861
|
+
type: parse.type('add numeric = numeric -> numeric'),
|
2862
|
+
impl: function(input, num) {
|
2863
|
+
return combine([input, num]).map(function(_arg) {
|
2864
|
+
var lhs, rhs;
|
2865
|
+
lhs = _arg[0], rhs = _arg[1];
|
2866
|
+
return Value.number(lhs.value + rhs.value);
|
2867
|
+
});
|
2868
|
+
}
|
2869
|
+
},
|
2870
|
+
sub: {
|
2871
|
+
type: parse.type('sub numeric = numeric -> numeric'),
|
2872
|
+
impl: function(input, num) {
|
2873
|
+
return combine([input, num]).map(function(_arg) {
|
2874
|
+
var lhs, rhs;
|
2875
|
+
lhs = _arg[0], rhs = _arg[1];
|
2876
|
+
return Value.number(lhs.value - rhs.value);
|
2877
|
+
});
|
2878
|
+
}
|
2879
|
+
},
|
2880
|
+
id: {
|
2881
|
+
type: parse.type('id = %a -> %a'),
|
2882
|
+
impl: function(x) {
|
2883
|
+
return x;
|
2884
|
+
}
|
2885
|
+
},
|
2886
|
+
"else": {
|
2887
|
+
type: parse.type('else = % -> bool'),
|
2888
|
+
impl: function(_) {
|
2889
|
+
return unit(vTrue);
|
2890
|
+
}
|
2891
|
+
},
|
2892
|
+
gt: {
|
2893
|
+
type: parse.type('gt numeric = numeric -> bool'),
|
2894
|
+
impl: function(input, num) {
|
2895
|
+
return combine([input, num]).map(function(_arg) {
|
2896
|
+
var lhs, rhs;
|
2897
|
+
lhs = _arg[0], rhs = _arg[1];
|
2898
|
+
return Value.boolean(lhs.value > rhs.value);
|
2899
|
+
});
|
2900
|
+
}
|
2901
|
+
},
|
2902
|
+
lt: {
|
2903
|
+
type: parse.type('lt numeric = numeric -> bool'),
|
2904
|
+
impl: function(input, num) {
|
2905
|
+
return combine([input, num]).map(function(_arg) {
|
2906
|
+
var lhs, rhs;
|
2907
|
+
lhs = _arg[0], rhs = _arg[1];
|
2908
|
+
return Value.boolean(lhs.value < rhs.value);
|
2909
|
+
});
|
2910
|
+
}
|
2911
|
+
},
|
2912
|
+
eq: {
|
2913
|
+
type: parse.type('eq %a = %a -> bool'),
|
2914
|
+
impl: function(input, obj) {
|
2915
|
+
return combine([input, obj]).then(function(_arg) {
|
2916
|
+
var lhs, rhs;
|
2917
|
+
lhs = _arg[0], rhs = _arg[1];
|
2918
|
+
return lhs.equals(rhs);
|
2919
|
+
});
|
2920
|
+
}
|
2921
|
+
}
|
2922
|
+
};
|
2923
|
+
})();
|
2924
|
+
// Generated by CoffeeScript 1.6.3
|
2849
2925
|
Gibbon.jsonConsumer = (function() {
|
2850
2926
|
return function(tables) {
|
2851
2927
|
var analyzeList, getType, getValue, lists;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodguide-gibbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: therubyracer
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 3075766379386117662
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: 3075766379386117662
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project: goodguide-gibbon
|
70
70
|
rubygems_version: 1.8.23
|