Apply and, apply or. Close 116

This commit is contained in:
2022-09-08 04:37:49 +00:00
parent 8962f72429
commit 2859c01e22
2 changed files with 22 additions and 0 deletions

View File

@@ -111,6 +111,8 @@ class Macros {
"zipDrop" => "Prelude.zipDrop",
"concat" => "Prelude.concat",
"intersect" => "Prelude.intersect",
"and" => "Prelude.and",
"or" => "Prelude.or"
];
k.doc("apply", 2, 2, '(apply <func> <argList>)' );
macros["apply"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k) -> {

View File

@@ -57,6 +57,26 @@ class Prelude {
};
}
static function _and(values:Array<Dynamic>):Dynamic {
for (value in values) {
if (!truthy(value)) {
return false;
}
}
return values[values.length - 1];
}
public static var and:Function = Reflect.makeVarArgs(_and);
static function _or(values:Array<Dynamic>):Dynamic {
for (value in values) {
if (truthy(value)) {
return value;
}
}
return false;
}
public static var or:Function = Reflect.makeVarArgs(_or);
// Kiss arithmetic will incur overhead because of these switch statements, but the results will not be platform-dependent
static function _add(values:Array<Dynamic>):Dynamic {
var sum:Dynamic = values[0];