help function displays values not

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-06 15:12:59 -08:00
parent 8d79037d4d
commit de29bbf950
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
6 changed files with 127 additions and 103 deletions

View file

@ -17,7 +17,11 @@
use crate::segment::{Ctr, Seg};
use crate::sym::{SymTable, ValueType};
pub fn bool_and_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
pub const AND_DOCSTRING: &str = "traverses a list of N arguments, all of which are expected to be boolean.
starts with arg1 AND arg2, and then calculates prev_result AND next_arg.
returns final result.";
pub fn and_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
let mut type_error = false;
let result = ast.circuit(&mut |arg: &Ctr| -> bool {
if let Ctr::Bool(b) = *arg {
@ -36,7 +40,11 @@ pub fn bool_and_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String>
}
}
pub fn bool_or_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
pub const OR_DOCSTRING: &str = "traverses a list of N arguments, all of which are expected to be boolean.
starts with arg1 OR arg2, and then calculates prev_result OR next_arg.
returns final result.";
pub fn or_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
let mut result = false;
let correct_types = ast.circuit(&mut |arg: &Ctr| -> bool {
if let Ctr::Bool(b) = *arg {
@ -55,7 +63,10 @@ pub fn bool_or_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String>
}
}
pub fn bool_not_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
pub const NOT_DOCSTRING: &str = "takes a single argument (expects a boolean).
returns false if arg is true or true if arg is false.";
pub fn not_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
if let Ctr::Bool(b) = *ast.car {
Ok(Ctr::Bool(!b))
} else {
@ -63,14 +74,23 @@ 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> {
pub const ISEQ_DOCSTRING: &str = "traverses a list of N arguments.
returns true if all arguments hold the same value.
NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't";
pub fn 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 }),
))
}
pub fn bool_toggle_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
pub const TOGGLE_DOCSTRING: &str = "switches a boolean symbol between true or false.
Takes a single argument (a symbol). Looks it up in the variable table.
Either sets the symbol to true if it is currently false, or vice versa.";
pub fn 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();