Skip to content

Commit

Permalink
Merge pull request #1937 from actonlang/re-enable-any-all
Browse files Browse the repository at this point in the history
Re-enable any() & all()
  • Loading branch information
plajjan authored Oct 8, 2024
2 parents 7eb2aea + b24f6cc commit 54ab03f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
22 changes: 11 additions & 11 deletions base/src/__builtin__.act
Original file line number Diff line number Diff line change
Expand Up @@ -840,17 +840,17 @@ extension bytes (Hashable):
def abs(x : Number) -> Real:
return x.__abs__()

#def all [A(value)] (it : Iterable[A]) -> bool:
# for x in it:
# if not x:
# return False
# return True

#def any [A(value)] (it : Iterable[A]) -> bool:
# for x in it:
# if x:
# return True
# return False
def all[A(value)](it: Iterable[A]) -> bool:
for x in it:
if bool(x) == False:
return False
return True

def any[A(value)](it: Iterable[A]) -> bool:
for x in it:
if bool(x) == True:
return True
return False

def ascii(x : value) -> str:
NotImplemented
Expand Down
23 changes: 23 additions & 0 deletions test/builtins_auto/test_all.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@




def test_all1():
stuff = [True, True, True]
if all(stuff):
return
raise ValueError("all stuff is True but all() returned False")

def test_all2():
stuff = [True, False, True]
if all(stuff):
raise ValueError("not all stuff is True but all() returned True")

actor main(env):
try:
test_all1()
test_all2()
env.exit(0)
except Exception as e:
print(e)
env.exit(1)
31 changes: 31 additions & 0 deletions test/builtins_auto/test_any.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@




def test_any1():
stuff = [True, True, True]
if any(stuff):
return
raise ValueError("all stuff is True but any() returned False")

def test_any2():
stuff = [True, False, True]
if any(stuff):
return
raise ValueError("some stuff is True but any() returned False")

def test_any3():
stuff = [False, False, False]
if any(stuff):
raise ValueError("no stuff is True but any() returned True")
return

actor main(env):
try:
test_any1()
test_any2()
test_any3()
env.exit(0)
except Exception as e:
print(e)
env.exit(1)

0 comments on commit 54ab03f

Please sign in to comment.