fix: 1-based indexing, babey
This commit is contained in:
parent
e25c9baa66
commit
a2210f2db3
2 changed files with 6 additions and 2 deletions
6
mute-interpreter/src/env/core.rs
vendored
6
mute-interpreter/src/env/core.rs
vendored
|
@ -334,7 +334,11 @@ pub(super) fn core() -> HashMap<String, Value> {
|
|||
}
|
||||
};
|
||||
|
||||
list.get(nth).unwrap().clone()
|
||||
if nth < 1 {
|
||||
return Node::Error(format!("TypeError: expected positive int, got {}", nth));
|
||||
}
|
||||
|
||||
list.get(nth - 1).unwrap().clone()
|
||||
}),
|
||||
),
|
||||
(
|
||||
|
|
|
@ -474,7 +474,7 @@ mod test {
|
|||
// List Manipulation
|
||||
#[case("(first (list 1 2 3))", "1")]
|
||||
#[case("(last (list 1 2 3))", "3")]
|
||||
#[case("(nth (list 1 2 3) 1)", "2")]
|
||||
#[case("(nth (list 1 2 3) 2)", "2")]
|
||||
#[case("(push-front (list 1 2 3) 0)", "(0 1 2 3)")]
|
||||
#[case("(push-back (list 1 2 3) 4)", "(1 2 3 4)")]
|
||||
#[case("(pop-front (list 1 2 3))", "(2 3)")]
|
||||
|
|
Loading…
Reference in a new issue