From ae16b30e6db80145cd44352f40a4498cb2f84f6e Mon Sep 17 00:00:00 2001 From: Vitor Date: Thu, 22 Aug 2024 16:38:54 -0300 Subject: [PATCH 1/3] add List/sum and List/range built-ins --- src/fun/builtins.bend | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index c6e830b8d..73579565d 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -47,6 +47,24 @@ List/filter (List/Cons x xs) pred = (List/filter xs pred) } +## Recursively sums all elements in a list of natural numbers. +# If the list is empty, returns 0. +# List/sum (xs: List(n24)) -> n24 +List/sum (List/Nil) = 0 +List/sum (List/Cons x xs) = (+ x (List/sum xs)) + +# Generates a list of natural numbers starting from `start` and ending at `end` (inclusive). +# If the start value is greater than the end value, returns an empty list. +# List/range (start: n24, end: n24) -> (List n24) +List/range start end = + if (> start end) { + (List/Nil) + } else { + (List/Cons start (List/range (+ start 1) end)) + } + + + # String/equals(s1: String, s2: String) -> u24 # Checks if two strings are equal. String/equals (String/Nil) (String/Nil) = 1 From 808bf110158304a655b91ee38aba9f2c89fc5b74 Mon Sep 17 00:00:00 2001 From: Sipher <77928770+Sipher@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:53:34 -0300 Subject: [PATCH 2/3] Update src/fun/builtins.bend Co-authored-by: Nicolas Abril --- src/fun/builtins.bend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index 73579565d..929ef0cd2 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -47,9 +47,9 @@ List/filter (List/Cons x xs) pred = (List/filter xs pred) } -## Recursively sums all elements in a list of natural numbers. +## Recursively sums all elements in a list of native numbers. # If the list is empty, returns 0. -# List/sum (xs: List(n24)) -> n24 +# List/sum (xs: List(Number(a))) -> Number(a) List/sum (List/Nil) = 0 List/sum (List/Cons x xs) = (+ x (List/sum xs)) From e4dab27ea59c8a6cde57f43105f278dbe7c247a6 Mon Sep 17 00:00:00 2001 From: Sipher <77928770+Sipher@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:53:40 -0300 Subject: [PATCH 3/3] Update src/fun/builtins.bend Co-authored-by: Nicolas Abril --- src/fun/builtins.bend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index 929ef0cd2..1639a676a 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -53,9 +53,9 @@ List/filter (List/Cons x xs) pred = List/sum (List/Nil) = 0 List/sum (List/Cons x xs) = (+ x (List/sum xs)) -# Generates a list of natural numbers starting from `start` and ending at `end` (inclusive). +# Generates a list of unsigned numbers starting from `start` and ending at `end` (inclusive). # If the start value is greater than the end value, returns an empty list. -# List/range (start: n24, end: n24) -> (List n24) +# List/range (start: u24, end: u24) -> (List u24) List/range start end = if (> start end) { (List/Nil)