@{
|
|
append(s, e) {
|
|
s[length(s)] = e;
|
|
}
|
|
|
|
map(f, seq, g) {
|
|
out = {};
|
|
if (g) {
|
|
for (i in seq) {
|
|
e = seq[i];
|
|
if (g(e)) { e = f(e); }
|
|
append(out, e);
|
|
}
|
|
} else {
|
|
for (i in seq) {
|
|
append(out, f(seq[i]));
|
|
}
|
|
}
|
|
out;
|
|
}
|
|
|
|
select(f, s) {
|
|
out = {};
|
|
for (i in s) {
|
|
e = s[i];
|
|
if (f(e)) { append(out, e); }
|
|
}
|
|
out;
|
|
}
|
|
|
|
reject(f, s) {
|
|
out = {};
|
|
for (i in s) {
|
|
e = s[i];
|
|
if (!f(e)) { append(out, e); }
|
|
}
|
|
out;
|
|
}
|
|
|
|
toChar(foo) {
|
|
"\"type :"+foo+"\"";
|
|
}
|
|
p2(foo) {
|
|
foo * foo;
|
|
}
|
|
c = ["earth", "sky", "water"];
|
|
isSky(x) { x == "sky" }
|
|
c = reject(isSky, c);
|
|
|
|
}
|
|
|
|
@{print(map(p2, [100, 2, 3]));}
|
|
|
|
@{print(map(toChar, c));}
|
|
|
|
enum foo { A, B, C };
|
|
enum oof { A, B, C };
|
|
|
|
@{
|
|
isEnum(x) { x.__proto__ == C_enum }
|
|
notToken(x) { x.__proto__ != Token }
|
|
to_C_string(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }}
|
|
// to_C_string(properties.enums.foo.enumList[?].name.identifier);
|
|
|
|
a = map(to_C_string, select(isEnum, properties.enums.foo.enumList));
|
|
b = map(to_C_string, properties.enums.foo.enumList, notToken);
|
|
c = map(to_C_string, properties.enums.foo.enumList, isEnum);
|
|
}
|
|
|
|
char *a[] = { @(a) };
|
|
|
|
char *b[] = { @(b) };
|
|
|
|
char *c[] = { @(c) };
|
|
|
|
|
|
|