2020-02-14 10:10:51 -05:00
|
|
|
use std::collections::BTreeMap;
|
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};
|
|
|
|
|
|
|
|
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|
|
|
decl!(f "length", |args, _| {
|
2020-02-16 22:04:54 -05:00
|
|
|
let len = match arg!(args, 0, "list") {
|
2020-02-14 10:10:51 -05:00
|
|
|
Value::List(v, _) => Number::from(v.len()),
|
|
|
|
_ => Number::from(1)
|
|
|
|
};
|
2020-02-16 10:14:17 -05:00
|
|
|
Ok(Value::Dimension(len, Unit::None))
|
2020-02-14 10:10:51 -05:00
|
|
|
});
|
|
|
|
}
|