Skip to content

Commit

Permalink
Merge pull request #1615 from actonlang/default-args-range
Browse files Browse the repository at this point in the history
Set range default step=1
  • Loading branch information
plajjan authored Jan 8, 2024
2 parents 0c16e8b + bb48c56 commit c01ec04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions base/builtin/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ B_NoneType B_rangeD___init__(B_range self, B_int start, B_int stop, B_int step)
}
if (step) {
int stp = from$int(step);
if (stp==0) {
$RAISE((B_BaseException)$NEW(B_ValueError,to$str("step size zero in range")));
}
else
if (stp == 0) {
$RAISE((B_BaseException)$NEW(B_ValueError, to$str("range() step size must not be zero")));
} else {
self->step = stp;
} else
}
} else {
self->step = 1;
}
return B_None;
}

Expand Down
12 changes: 11 additions & 1 deletion base/src/__builtin__.act
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ class list[A] (object):
NotImplemented

class range (value):
def __init__(self, start: int, stop: ?int, step: ?int) -> None:
"""Return an object that produces a sequence of integers from start
(inclusive) to stop (exclusive) in step sizes as specified by the step
argument, which is 1 per default. It is possible to call with just a single
argument like `range(j)` where `j` is then interpreted to be the stop
argument with an implicit default start of 0.

- `range(0, 3, 1)` produces [0, 1, 2]
- `range(0, 3)` produces [0, 1, 2]
- `range(3)` produces [0, 1, 2]
"""
def __init__(self, start: int, stop: ?int, step: int=1) -> None:
NotImplemented

class Iterator[A] (object):
Expand Down

0 comments on commit c01ec04

Please sign in to comment.