From 889705baaab3689c5dc052565857b7f7fba05b76 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 5 Aug 2024 10:04:17 +0200 Subject: [PATCH] reverse the arguments of cons_end so it fit better with the revers call operator --- book/src/list-functions-lists.md | 2 +- examples/tests/lists.nbt | 4 ++-- numbat/modules/core/lists.nbt | 4 ++-- numbat/src/ffi/lists.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/book/src/list-functions-lists.md b/book/src/list-functions-lists.md index ad9a7399..10723fa0 100644 --- a/book/src/list-functions-lists.md +++ b/book/src/list-functions-lists.md @@ -34,7 +34,7 @@ fn cons(x: A, xs: List) -> List Append an element to the end of a list. ```nbt -fn cons_end(xs: List, x: A) -> List +fn cons_end(x: A, xs: List) -> List ``` ### `is_empty` diff --git a/examples/tests/lists.nbt b/examples/tests/lists.nbt index 22ba39c6..f4043c02 100644 --- a/examples/tests/lists.nbt +++ b/examples/tests/lists.nbt @@ -10,8 +10,8 @@ assert_eq(tail(xs), [2, 3]) assert_eq(cons(0, xs), [0, 1, 2, 3]) -assert_eq(cons_end(xs, 4), [1, 2, 3, 4]) -assert_eq(cons_end([], 0), [0]) +assert_eq(cons_end(4, xs), [1, 2, 3, 4]) +assert_eq(cons_end(0, []), [0]) assert(is_empty([])) assert(!is_empty(xs)) diff --git a/numbat/modules/core/lists.nbt b/numbat/modules/core/lists.nbt index 3cba05e8..24e2217e 100644 --- a/numbat/modules/core/lists.nbt +++ b/numbat/modules/core/lists.nbt @@ -15,7 +15,7 @@ fn tail(xs: List) -> List fn cons(x: A, xs: List) -> List @description("Append an element to the end of a list") -fn cons_end(xs: List, x: A) -> List +fn cons_end(x: A, xs: List) -> List @description("Check if a list is empty") fn is_empty(xs: List) -> Bool = xs == [] @@ -55,7 +55,7 @@ fn range(start: Scalar, end: Scalar) -> List = fn reverse(xs: List) -> List = if is_empty(xs) then [] - else cons_end(reverse(tail(xs)), head(xs)) + else cons_end(head(xs), reverse(tail(xs))) @description("Generate a new list by applying a function to each element of the input list") fn map(f: Fn[(A) -> B], xs: List) -> List = diff --git a/numbat/src/ffi/lists.rs b/numbat/src/ffi/lists.rs index ae4e0292..609465c9 100644 --- a/numbat/src/ffi/lists.rs +++ b/numbat/src/ffi/lists.rs @@ -36,8 +36,8 @@ pub fn cons(mut args: Args) -> Result { } pub fn cons_end(mut args: Args) -> Result { - let mut list = list_arg!(args); let element = arg!(args); + let mut list = list_arg!(args); list.push_back(element); return_list!(list)