ksl 0.1.30

KSL core library and interpreter
Documentation
//! # ksl::builtin::chars
//!
//! Built-in function `Chars`.

use crate::{Environment, eval::apply::eval_apply, value::Value};

pub(crate) fn builtin(args: &[Value], env: Environment) -> Result<Value, std::sync::Arc<str>> {
    if let [val] = args {
        match eval_apply(val, env)? {
            Value::String(s) => Ok(Value::List(
                s.chars()
                    .map(|c| Value::String(std::sync::Arc::from(c.to_string())))
                    .collect::<std::sync::Arc<[Value]>>(),
            )),
            e => Err(std::sync::Arc::from(format!(
                concat!("Error[ksl::builtin::Chars]: ", "Unexpected value: `{}`."),
                e
            ))),
        }
    } else {
        Err(std::sync::Arc::from(format!(
            concat!(
                "Error[ksl::builtin::Chars]: ",
                "Expected 1 parameter, but {} were passed."
            ),
            args.len()
        )))
    }
}