1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use r_derive::*;

use crate::callable::core::*;
use crate::formals;
use crate::lang::*;
use crate::object::*;

#[doc(alias = "typeof")]
#[builtin(sym = "typeof")]
#[derive(Debug, Clone, PartialEq)]
pub struct PrimitiveTypeOf;

formals!(PrimitiveTypeOf, "(x,)");

impl Callable for PrimitiveTypeOf {
    fn call_matched(&self, args: List, _ellipsis: List, stack: &mut CallStack) -> EvalResult {
        let mut args = Obj::List(args);
        let x = args.try_get_named("x")?.force(stack)?;
        EvalResult::Ok(Obj::Vector(Vector::Character(vec![x.type_of()].into())))
    }
}

#[cfg(test)]

mod tests {
    use crate::{r, r_expect};
    #[test]
    fn character() {
        r_expect!(typeof("a") == "character")
    }
}