add list type check
This commit is contained in:
parent
e3875d4652
commit
0babc1986a
4 changed files with 56 additions and 2 deletions
|
|
@ -180,6 +180,15 @@ fn reverse_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
}
|
||||
}
|
||||
|
||||
const ISLIST_DOCSTRING: &str = "takes a single argument, returns true if argument is a list";
|
||||
fn islist_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
||||
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()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue