use r_derive::*;
use crate::callable::core::*;
use crate::formals;
use crate::lang::*;
use crate::object::types::Logical;
use crate::object::*;
#[doc(alias = "is_null")]
#[builtin(sym = "is_null")]
#[derive(Debug, Clone, PartialEq)]
pub struct PrimitiveIsNull;
formals!(PrimitiveIsNull, "(x)");
impl Callable for PrimitiveIsNull {
    fn call(&self, args: ExprList, stack: &mut CallStack) -> EvalResult {
        let (args, _ellipsis) = self.match_arg_exprs(args, stack)?;
        let mut args = Obj::List(args);
        let x = args.try_get_named("x")?.force(stack)?;
        EvalResult::Ok(Obj::Vector(Vector::from(vec![Logical::Some(matches!(
            x,
            Obj::Null
        ))])))
    }
}
#[cfg(test)]
mod tests {
    use crate::{r, r_expect};
    #[test]
    fn is_null() {
        r_expect!(is_null(null))
    }
    #[test]
    fn is_not_null() {
        r_expect!(!is_null(1:2))
    }
}