help function displays values not
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
8d79037d4d
commit
de29bbf950
6 changed files with 127 additions and 103 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue