rl_lang/interpreter/stdlib/array/
arr_pop.rs1use crate::{
2 interpreter::{evaluator::Evaluator, values::Value},
3 utils::{errors::Error, span::Span},
4};
5
6pub fn std_arr_pop(eval: &mut Evaluator, array: Value, span: Span) -> Result<Value, Error> {
7 match array {
8 Value::Values {
9 items_type,
10 mut items,
11 } => {
12 if items.is_empty() {
13 return Err(eval.err("arr_pop() called on empty array".to_string(), span));
14 }
15 items.pop();
16 Ok(Value::Values { items_type, items })
17 }
18 _ => Err(eval.err("arr_pop() accepts only arrays".to_string(), span)),
19 }
20}