Readme and clippy cleanups
This commit is contained in:
parent
cbd52de91b
commit
8cc0202a7b
13 changed files with 159 additions and 197 deletions
105
src/stl/decl.rs
105
src/stl/decl.rs
|
|
@ -48,7 +48,7 @@ fn eval_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
Err(e) => Err(e.with_trace(
|
||||
("eval", "evaluation failure")
|
||||
.into())),
|
||||
Ok(s) => Ok(*s.clone()),
|
||||
Ok(s) => Ok(*s),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ fn eval_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
Err(e) => Err(e.with_trace(
|
||||
("eval", "evaluation failure")
|
||||
.into())),
|
||||
Ok(s) => Ok(*s.clone()),
|
||||
Ok(s) => Ok(*s),
|
||||
}
|
||||
} else {
|
||||
Ok(res)
|
||||
|
|
@ -101,7 +101,7 @@ fn help_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
return Err(start_trace(("help", "expected one input").into()));
|
||||
}
|
||||
if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
if let Some(ref sym) = syms.get(symbol) {
|
||||
if let Some(sym) = syms.get(symbol) {
|
||||
let args_str: String;
|
||||
if let ValueType::VarForm(_) = sym.value {
|
||||
args_str = "(its a variable)".to_string();
|
||||
|
|
@ -132,16 +132,10 @@ returns true or false according to whether or not the symbol is found in the sym
|
|||
fn isset_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
||||
if ast.len() != 1 {
|
||||
Err(start_trace(("set?", "expcted one input").into()))
|
||||
} else if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
Ok(Ctr::Bool(syms.get(symbol).is_some()))
|
||||
} 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(start_trace(("set?", "expected argument to be a input").into()))
|
||||
}
|
||||
Err(start_trace(("set?", "expected argument to be a input").into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,12 +160,11 @@ fn env_callback(_ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
let mut variables = vec![];
|
||||
for (name, val) in syms.iter() {
|
||||
if let ValueType::VarForm(l) = &val.value {
|
||||
let token: String;
|
||||
match l.to_type() {
|
||||
Type::Lambda => token = format!("{}: <lambda>", name),
|
||||
Type::Seg => token = format!("{}: <form>", name),
|
||||
_ => token = format!("{}: {}", name, val.value.to_string()),
|
||||
}
|
||||
let token: String = match l.to_type() {
|
||||
Type::Lambda => format!("{}: <lambda>", name),
|
||||
Type::Seg => format!("{}: <form>", name),
|
||||
_ => format!("{}: {}", name, val.value),
|
||||
};
|
||||
|
||||
if token.len() > v_col_len && token.len() < xdim as usize {
|
||||
v_col_len = token.len();
|
||||
|
|
@ -203,7 +196,7 @@ fn env_callback(_ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
print!("{:v_col_len$}", var);
|
||||
col_iter += 1;
|
||||
if col_iter % n_v_cols == 0 {
|
||||
print!("\n");
|
||||
println!();
|
||||
} else {
|
||||
print!(" ");
|
||||
}
|
||||
|
|
@ -214,7 +207,7 @@ fn env_callback(_ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
print!("{:f_col_len$}", func);
|
||||
col_iter += 1;
|
||||
if col_iter % n_f_cols == 0 {
|
||||
print!("\n");
|
||||
println!();
|
||||
} else {
|
||||
print!(" ");
|
||||
}
|
||||
|
|
@ -250,19 +243,17 @@ fn lambda_callback(
|
|||
}
|
||||
}) {
|
||||
Err(start_trace(("lambda", "lambda inputs should all be symbols").into()))
|
||||
} else {
|
||||
if let Ctr::Seg(ref eval_head) = *ast.cdr {
|
||||
if let Ctr::Seg(_) = *eval_head.car {
|
||||
Ok(Ctr::Lambda(UserFn{
|
||||
ast: Box::new(eval_head.clone()),
|
||||
arg_syms: args,
|
||||
}))
|
||||
} else {
|
||||
Err(start_trace(("lambda", "expected list of forms for lambda body").into()))
|
||||
}
|
||||
} else if let Ctr::Seg(ref eval_head) = *ast.cdr {
|
||||
if let Ctr::Seg(_) = *eval_head.car {
|
||||
Ok(Ctr::Lambda(UserFn{
|
||||
ast: Box::new(eval_head.clone()),
|
||||
arg_syms: args,
|
||||
}))
|
||||
} else {
|
||||
Err(start_trace(("lambda", "not enough args").into()))
|
||||
Err(start_trace(("lambda", "expected list of forms for lambda body").into()))
|
||||
}
|
||||
} else {
|
||||
Err(start_trace(("lambda", "not enough args").into()))
|
||||
}
|
||||
} else {
|
||||
Err(start_trace(("lambda", "expected list of lambda inputs").into()))
|
||||
|
|
@ -296,36 +287,33 @@ fn setdoc_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
Err(start_trace(
|
||||
("set-doc", "expected two inputs")
|
||||
.into()))
|
||||
} else {
|
||||
if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
if let Some(mut sym) = syms.remove(symbol) {
|
||||
if let Ctr::Seg(ref doc_node) = *ast.cdr {
|
||||
if let Ctr::String(ref doc) = *doc_node.car {
|
||||
sym.docs = doc.clone();
|
||||
syms.insert(sym.name.clone(), sym);
|
||||
Ok(Ctr::None)
|
||||
} else {
|
||||
syms.insert(sym.name.clone(), sym);
|
||||
Err(start_trace(
|
||||
("set-doc", "expected second input to be a string")
|
||||
.into()))
|
||||
}
|
||||
} else if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
if let Some(mut sym) = syms.remove(symbol) {
|
||||
if let Ctr::Seg(ref doc_node) = *ast.cdr {
|
||||
if let Ctr::String(ref doc) = *doc_node.car {
|
||||
sym.docs = doc.clone();
|
||||
syms.insert(sym.name.clone(), sym);
|
||||
Ok(Ctr::None)
|
||||
} else {
|
||||
syms.insert(sym.name.clone(), sym);
|
||||
Err(start_trace(
|
||||
("set-doc", "missing second input somehow")
|
||||
("set-doc", "expected second input to be a string")
|
||||
.into()))
|
||||
}
|
||||
} else {
|
||||
Err(start_trace(
|
||||
("set-doc", format!("{symbol} is undefined"))
|
||||
("set-doc", "missing second input somehow")
|
||||
.into()))
|
||||
}
|
||||
|
||||
} else {
|
||||
Err(start_trace(
|
||||
("set-doc", "first input must be a symbol")
|
||||
("set-doc", format!("{symbol} is undefined"))
|
||||
.into()))
|
||||
}
|
||||
} else {
|
||||
Err(start_trace(
|
||||
("set-doc", "first input must be a symbol")
|
||||
.into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -377,10 +365,8 @@ fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
}
|
||||
|
||||
return Ok(Ctr::None)
|
||||
} else {
|
||||
if ast.len() < 3 || ast.len() > 4 {
|
||||
return Err(start_trace(("def", "expected 3 or 4 inputs").into()))
|
||||
}
|
||||
} else if ast.len() < 3 || ast.len() > 4 {
|
||||
return Err(start_trace(("def", "expected 3 or 4 inputs").into()))
|
||||
}
|
||||
|
||||
let mut iter: &Seg;
|
||||
|
|
@ -394,7 +380,7 @@ fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
Ctr::String(ref s) => docs = s.clone(),
|
||||
Ctr::Symbol(ref s) => match syms.call_symbol(s, &Seg::new(), true) {
|
||||
Ok(d) => if let Ctr::String(doc) = *d {
|
||||
docs = doc.clone();
|
||||
docs = doc;
|
||||
} else {
|
||||
return Err(start_trace(("def", "expected docs input to evaluate to a string").into()))
|
||||
},
|
||||
|
|
@ -432,7 +418,6 @@ fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
}
|
||||
|
||||
if is_var {
|
||||
let var_val: Ctr;
|
||||
let var_eval_result = eval(var_val_form, syms);
|
||||
if let Err(e) = var_eval_result {
|
||||
return Err(e.with_trace(
|
||||
|
|
@ -440,11 +425,11 @@ fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
.into()))
|
||||
}
|
||||
let var_eval_final = *var_eval_result?;
|
||||
match var_eval_final {
|
||||
Ctr::Seg(ref s) if expand => var_val = *s.car.clone(),
|
||||
Ctr::Seg(ref s) if !expand => var_val = Ctr::Seg(s.clone()),
|
||||
_ => var_val = var_eval_final,
|
||||
}
|
||||
let var_val: Ctr = match var_eval_final {
|
||||
Ctr::Seg(ref s) if expand => *s.car.clone(),
|
||||
Ctr::Seg(ref s) if !expand => Ctr::Seg(s.clone()),
|
||||
_ => var_eval_final,
|
||||
};
|
||||
|
||||
let outer_seg = Seg::from_mono(Box::new(var_val.clone()));
|
||||
syms.insert(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue