diff --git a/Readme.org b/Readme.org index 0d8d505..7471c66 100644 --- a/Readme.org +++ b/Readme.org @@ -155,7 +155,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt ** DONE Beta tasks (See tag: v0.3.0) ** TODO v1.0 tasks -- islist type query - set library - Can pass args to relish scripts (via interpreter) - Can pass args to relish scripts (via command line) diff --git a/Writing.org b/Writing.org index 91c826c..fa58ad2 100644 --- a/Writing.org +++ b/Writing.org @@ -299,7 +299,7 @@ The following table is up to date as of Relish 0.3.0. For latest information try |----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------| | | | | pop | gte? | string | | cond | | | |----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------| -| | | | | int | | | | | | +| | | | list? | int | | | | | | |----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------| | | | | | mod | | | | | | |----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------| diff --git a/src/stl/append.rs b/src/stl/append.rs index f5de4ef..cf0c4bf 100644 --- a/src/stl/append.rs +++ b/src/stl/append.rs @@ -180,6 +180,15 @@ fn reverse_callback(ast: &Seg, _syms: &mut SymTable) -> Result { } } +const ISLIST_DOCSTRING: &str = "takes a single argument, returns true if argument is a list"; +fn islist_callback(ast: &Seg, _syms: &mut SymTable) -> Result { + if let Ctr::Seg(_) = *ast.car { + Ok(Ctr::Bool(true)) + } else { + Ok(Ctr::Bool(false)) + } +} + pub fn add_list_lib(syms: &mut SymTable) { syms.insert( "cons".to_string(), @@ -264,4 +273,16 @@ pub fn add_list_lib(syms: &mut SymTable) { ..Default::default() }, ); + + syms.insert( + "list?".to_string(), + Symbol { + name: String::from("list?"), + args: Args::Lazy(1), + conditional_branches: false, + docs: ISLIST_DOCSTRING.to_string(), + value: ValueType::Internal(Rc::new(islist_callback)), + ..Default::default() + }, + ); } diff --git a/tests/test_lib_append.rs b/tests/test_lib_append.rs index ebc6346..f3c4431 100644 --- a/tests/test_lib_append.rs +++ b/tests/test_lib_append.rs @@ -328,4 +328,38 @@ mod append_lib_tests { result.to_string(), ); } + + #[test] + fn test_islist_t() { + let document = "(list? ())"; + let result = "true"; + + let mut syms = SymTable::new(); + static_stdlib(&mut syms); + dynamic_stdlib(&mut syms, None); + + assert_eq!( + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), + result.to_string(), + ); + } + + #[test] + fn test_islist_f() { + let document = "(list? 1223)"; + let result = "false"; + + let mut syms = SymTable::new(); + static_stdlib(&mut syms); + dynamic_stdlib(&mut syms, None); + + assert_eq!( + *eval(&lex(&document.to_string()).unwrap(), &mut syms) + .unwrap() + .to_string(), + result.to_string(), + ); + } }