finished circuit form
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
c235f9727f
commit
4b587f11ab
7 changed files with 144 additions and 53 deletions
|
|
@ -65,28 +65,32 @@ pub fn bool_not_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String>
|
|||
|
||||
pub fn bool_iseq_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let head_ctr_ref = &*ast.car;
|
||||
Ok(Ctr::Bool(ast.circuit(&mut |arg: &Ctr| -> bool {arg == head_ctr_ref})))
|
||||
Ok(Ctr::Bool(
|
||||
ast.circuit(&mut |arg: &Ctr| -> bool { arg == head_ctr_ref }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn bool_toggle_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let var_name: String;
|
||||
if let Ctr::Symbol(ref s) = *ast.car {
|
||||
var_name = s.clone();
|
||||
if let Ctr::Symbol(ref s) = *ast.car {
|
||||
var_name = s.clone();
|
||||
} else {
|
||||
return Err("argument to toggle should be a symbol".to_string())
|
||||
return Err("argument to toggle should be a symbol".to_string());
|
||||
}
|
||||
|
||||
let mut sym = syms.remove(&var_name).expect(&format!("symbol {var_name} is not defined"));
|
||||
let mut sym = syms
|
||||
.remove(&var_name)
|
||||
.expect(&format!("symbol {var_name} is not defined"));
|
||||
if let ValueType::VarForm(ref var) = sym.value {
|
||||
if let Ctr::Bool(ref b) = **var {
|
||||
sym.value = ValueType::VarForm(Box::new(Ctr::Bool(!b)));
|
||||
} else {
|
||||
syms.insert(var_name, sym);
|
||||
return Err("can only toggle a boolean".to_string())
|
||||
return Err("can only toggle a boolean".to_string());
|
||||
}
|
||||
} else {
|
||||
syms.insert(var_name, sym);
|
||||
return Err("cannot toggle a function".to_string())
|
||||
return Err("cannot toggle a function".to_string());
|
||||
}
|
||||
|
||||
syms.insert(var_name, sym);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue