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
|
|
@ -19,6 +19,15 @@ use crate::eval::eval;
|
|||
use crate::segment::{Ctr, Seg};
|
||||
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
||||
|
||||
pub const IF_DOCSTRING: &str = "accepts three bodies, a condition, an unevaluated consequence, and an alternative consequence.
|
||||
If the condition is evaluated to true, the first consequence is evaluated.
|
||||
If the condition is evaluated to false, the second consequence is evaluated.
|
||||
Otherwise, an error is thrown.
|
||||
|
||||
example: (if my-state-switch
|
||||
(do-my-thing)
|
||||
(else-an-other-thing))";
|
||||
|
||||
pub fn if_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let cond: bool;
|
||||
println!("Y: {}", *ast.car);
|
||||
|
|
@ -85,6 +94,20 @@ pub fn if_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub const LET_DOCSTRING: &str = "creates a stack of local variables for a sequence of operations.
|
||||
returns the result of the final operation.
|
||||
|
||||
example: (let ((step1 'hello')
|
||||
(step2 (concat step1 '-'))
|
||||
(step3 (concat step2 'world')))
|
||||
(echo step3)
|
||||
(some-func some-args))
|
||||
|
||||
In this example step1, step2, and step3 are created sequentially.
|
||||
Then, the echo form is evaluated, printing 'hello-world'.
|
||||
Finally, the some-func form is evaluated.
|
||||
Since the call to some-func is the final form, its value is returned.";
|
||||
|
||||
pub fn let_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let mut localsyms = syms.clone();
|
||||
let locals_form: &Seg;
|
||||
|
|
@ -180,9 +203,14 @@ pub fn let_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
Ok((*result).clone())
|
||||
}
|
||||
|
||||
/*
|
||||
(while (cond) evalme evalme evalme evalme ... )
|
||||
*/
|
||||
pub const WHILE_DOCSTRING: &str = "traverses a list of N un-evaluated forms.
|
||||
the first form is expected to evaluate to a boolean. if it evaluates to false, while will stop and return. Otherwise, while will evaluate each form in a loop.
|
||||
|
||||
example: (while (check-my-state)
|
||||
(do-thing-1 args)
|
||||
(do-thing-2 args)
|
||||
(edit-state my-state))";
|
||||
|
||||
pub fn while_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let eval_cond: &Seg;
|
||||
let outer_maybe: Seg;
|
||||
|
|
@ -244,9 +272,17 @@ pub fn while_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
Ok(*(result.unwrap()).clone())
|
||||
}
|
||||
|
||||
/*
|
||||
(circuit makes_a_bool makes_a_bool makes_a_bool makes_a_bool ... )
|
||||
*/
|
||||
pub const CIRCUIT_DOCSTRING: &str = "traverses a list of N un-evaluated forms.
|
||||
evaluates each one until it stops. Circuit will stop when a form errors during evaluation.
|
||||
Circuit will also stop when a form does not evaluate to a boolean, or evaluates to false.
|
||||
|
||||
example: (circuit (eq? (do-operation) myresult)
|
||||
(and state1 state2 (boolean-operation3))
|
||||
false
|
||||
(do-another-operation))
|
||||
|
||||
in this example, do-another-operation will not be called";
|
||||
|
||||
pub fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let mut cursor = 0;
|
||||
let mut error: String = String::new();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue