Skip to content

Commit

Permalink
Keep existing min & max signature
Browse files Browse the repository at this point in the history
Temporarily back out the change of removing default value to max & min
since it breaks existing code. We should only introduce the next max_def
& min_def functions, switch over to using them and once that is done we
can change min & max.
  • Loading branch information
Kristian Larsson committed Dec 12, 2024
1 parent f56d102 commit 96601ea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions base/builtin/builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ B_Iterator B_map(B_Iterable wit, $pure f, $WORD iter) {

// max, min ///////////////////////////////////////////////////////////////////////////////////

$WORD B_max(B_Ord wit, B_Iterable wit2, $WORD iter) {
$WORD res = NULL;
$WORD B_max(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD dflt) {
$WORD res = dflt;
B_Iterator it = wit2->$class->__iter__(wit2,iter);
while(1) {
if ($PUSH()) {
Expand Down Expand Up @@ -271,8 +271,8 @@ B_Iterator B_map(B_Iterable wit, $pure f, $WORD iter) {
return res;
}

$WORD B_min(B_Ord wit, B_Iterable wit2, $WORD iter) {
$WORD res = NULL;
$WORD B_min(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD dflt) {
$WORD res = dflt;
B_Iterator it = wit2->$class->__iter__(wit2,iter);
while(1) {
if ($PUSH()) {
Expand All @@ -284,8 +284,8 @@ B_Iterator B_map(B_Iterable wit, $pure f, $WORD iter) {
B_BaseException ex = $POP();
if ($ISINSTANCE0(ex, B_StopIteration))
break;
else
$RAISE(ex);
else
$RAISE(ex);
}
}
return res;
Expand All @@ -304,8 +304,8 @@ B_Iterator B_map(B_Iterable wit, $pure f, $WORD iter) {
B_BaseException ex = $POP();
if ($ISINSTANCE0(ex, B_StopIteration))
break;
else
$RAISE(ex);
else
$RAISE(ex);
}
}
return res;
Expand Down
4 changes: 2 additions & 2 deletions base/builtin/builtin_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ struct $IdentityActor {

// Various small functions //////////////////////////////////////////////////////////

$WORD B_min(B_Ord wit, B_Iterable wit2, $WORD iter);
$WORD B_max(B_Ord wit, B_Iterable wit2, $WORD iter);
$WORD B_min(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);
$WORD B_max(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);
$WORD B_min_def(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);
$WORD B_max_def(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);

Expand Down
4 changes: 2 additions & 2 deletions base/src/__builtin__.act
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,10 @@ def len(x : Collection[A]) -> int:
def map(function: (A) -> B, iterable: Iterable[A]) -> Iterator[B]:
NotImplemented

def max [A(Ord)] (iter: Iterable[A]) -> ?A:
def max [A(Ord)] (iter: Iterable[A], dflt: ?A) -> ?A:
NotImplemented

def min [A(Ord)] (iter: Iterable[A]) -> ?A:
def min [A(Ord)] (iter: Iterable[A], dflt: ?A) -> ?A:
NotImplemented

def max_def [A(Ord)] (iter: Iterable[A], dflt: A) -> A:
Expand Down
2 changes: 1 addition & 1 deletion test/builtins_auto/builtin_functions_test.act
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actor main(env):
if list(map(lambda x : x*x,lst)) != [100, 121, 144, 169, 196]:
print("map")
env.exit(1)
a = max(lst)
a = max(lst, None)
if a is None or a != 14:
print("max")
env.exit(1)
Expand Down

0 comments on commit 96601ea

Please sign in to comment.