use crate::lang::adapter::Adapter;
use crate::lang::args::eval_string_args;
use crate::lang::arity::Arity;
use crate::lang::arity::assert_func_arity;
use crate::lang::error::Error;
use crate::lang::machine::Machine;
use crate::lang::node::Node;
use crate::value::Value;
pub(crate) fn replace(
adapter: &impl Adapter,
machine: &mut Machine<'_>,
stdin: Option<&Value>,
node: Node,
) -> Result<Value, Error> {
assert_func_arity(adapter, machine, stdin, &node, &Arity::new(3))?;
let mut args = eval_string_args(adapter, machine, stdin, node)?.unwrap_or_default();
let value = args.pop().unwrap_or_default();
let to = args.pop().unwrap_or_default();
let from = args.pop().unwrap_or_default();
let value = value.replace(&from, &to);
Ok(value.into())
}