Skip to content

Commit

Permalink
reverse the arguments of cons_end so it fit better with the revers ca…
Browse files Browse the repository at this point in the history
…ll operator
  • Loading branch information
irevoire committed Aug 5, 2024
1 parent 5667a30 commit 889705b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion book/src/list-functions-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn cons<A>(x: A, xs: List<A>) -> List<A>
Append an element to the end of a list.

```nbt
fn cons_end<A>(xs: List<A>, x: A) -> List<A>
fn cons_end<A>(x: A, xs: List<A>) -> List<A>
```

### `is_empty`
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/lists.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions numbat/modules/core/lists.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn tail<A>(xs: List<A>) -> List<A>
fn cons<A>(x: A, xs: List<A>) -> List<A>

@description("Append an element to the end of a list")
fn cons_end<A>(xs: List<A>, x: A) -> List<A>
fn cons_end<A>(x: A, xs: List<A>) -> List<A>

@description("Check if a list is empty")
fn is_empty<A>(xs: List<A>) -> Bool = xs == []
Expand Down Expand Up @@ -55,7 +55,7 @@ fn range(start: Scalar, end: Scalar) -> List<Scalar> =
fn reverse<A>(xs: List<A>) -> List<A> =
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<A, B>(f: Fn[(A) -> B], xs: List<A>) -> List<B> =
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/ffi/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn cons(mut args: Args) -> Result<Value> {
}

pub fn cons_end(mut args: Args) -> Result<Value> {
let mut list = list_arg!(args);
let element = arg!(args);
let mut list = list_arg!(args);
list.push_back(element);

return_list!(list)
Expand Down

0 comments on commit 889705b

Please sign in to comment.