add isset
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
de29bbf950
commit
8d6915f69a
2 changed files with 57 additions and 0 deletions
30
src/stl.rs
30
src/stl.rs
|
|
@ -162,6 +162,17 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"set?".to_string(),
|
||||
Symbol {
|
||||
name: String::from("set?"),
|
||||
args: Args::Strict(vec![Type::Symbol]),
|
||||
conditional_branches: true,
|
||||
docs: ISSET_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(_isset_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -356,3 +367,22 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
}
|
||||
Ok(Ctr::None)
|
||||
}
|
||||
|
||||
pub const ISSET_DOCSTRING: &str = "accepts a single argument: a symbol.
|
||||
returns true or false according to whether or not the symbol is found in the symbol table.";
|
||||
|
||||
fn _isset_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
if ast.len() != 1 {
|
||||
Err("help only takes a single argument".to_string())
|
||||
} else {
|
||||
if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
if let Some(_) = syms.get(symbol) {
|
||||
Ok(Ctr::Bool(true))
|
||||
} else {
|
||||
Ok(Ctr::Bool(false))
|
||||
}
|
||||
} else {
|
||||
Err("help should only be called on a symbol".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue