(range...) does not need to be a macro
Some checks failed
CI / test (push) Failing after 55s
CI / test-core (14, ubuntu-latest, 3.x, nodejs) (push) Failing after 1m38s
CI / test-core (14, ubuntu-latest, 3.x, js) (push) Failing after 1m39s
CI / test-core (14, ubuntu-latest, 3.x, interp) (push) Failing after 2m3s
CI / test-core (14, ubuntu-latest, 3.x, cpp) (push) Failing after 2m15s
CI / test-core (14, ubuntu-latest, 3.x, py) (push) Failing after 1m48s

This commit is contained in:
2025-11-11 09:25:15 -06:00
parent 2c53e74229
commit b1a31958fa
3 changed files with 5 additions and 10 deletions

View File

@@ -84,6 +84,7 @@ class Kiss {
"print" => Symbol("Prelude.print"),
"sort" => Symbol("Prelude.sort"),
"sortBy" => Symbol("Prelude.sortBy"),
"range" => Symbol("Prelude.range"),
"groups" => Symbol("Prelude.groups"),
"pairs" => Symbol("Prelude.pairs"),
"reverse" => Symbol("Prelude.reverse"),

View File

@@ -145,15 +145,6 @@ class Macros {
exp;
};
k.doc("range", 1, 3, '(range <?min> <max> <?step>)');
macros["range"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k) -> {
var b = wholeExp.expBuilder();
var min = if (exps.length > 1) exps[0] else b.symbol("0");
var max = if (exps.length > 1) exps[1] else exps[0];
var step = if (exps.length > 2) exps[2] else b.symbol("1");
b.callSymbol("Prelude.range", [min, max, step]);
};
function prepareForConditional(i:KissInterp, k:KissState) {
i.variables.set("kissFile", k.file);
i.variables.set("className", k.className);

View File

@@ -411,10 +411,13 @@ class Prelude {
}
// Ranges with a min, exclusive max, and step size, just like Python.
public static function range(min, max, step):Iterator<Int>
public static function range(min, ?max, ?step):Iterator<Int>
& Iterable<Int>
{
if(step == null) step = 1;
if(max == null) { max = min; min = 0; }
if (step <= 0 || max < min)
throw "(range...) can only count up";
var count = min;