2020-03-03 19:51:02 -05:00
|
|
|
use std::collections::HashMap;
|
2020-02-02 21:09:29 -05:00
|
|
|
|
2020-02-14 10:10:51 -05:00
|
|
|
use super::Builtin;
|
|
|
|
use crate::units::Unit;
|
|
|
|
use crate::value::{Number, Value};
|
|
|
|
|
2020-03-03 19:51:02 -05:00
|
|
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
2020-03-16 10:35:38 -04:00
|
|
|
f.insert(
|
|
|
|
"length".to_owned(),
|
|
|
|
Box::new(|args, _| {
|
|
|
|
let len = match arg!(args, 0, "list") {
|
|
|
|
Value::List(v, _) => Number::from(v.len()),
|
|
|
|
_ => Number::from(1),
|
|
|
|
};
|
|
|
|
Ok(Value::Dimension(len, Unit::None))
|
|
|
|
}),
|
|
|
|
);
|
2020-02-14 10:10:51 -05:00
|
|
|
}
|