implementations for quote and eval

This commit is contained in:
Ava Hahn 2023-03-10 16:54:22 -08:00
parent 61a1b47b85
commit 6daf0867df
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
2 changed files with 46 additions and 6 deletions

View file

@ -20,6 +20,26 @@ use crate::segment::{Ctr, Seg};
use crate::sym::{Args, SymTable, Symbol, UserFn, ValueType};
use std::env;
pub const QUOTE_DOCSTRING: &str = "takes a single unevaluated tree and returns it as it is: unevaluated.";
pub fn quote_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
if ast.len() > 1 {
Err("do not quote more than one thing at a time".to_string())
} else {
Ok(Ctr::Seg(ast.clone()))
}
}
pub const EVAL_DOCSTRING: &str = "takes an unevaluated argument and evaluates it.";
pub fn eval_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
if ast.len() > 1 {
Err("do not quote more than one thing at a time".to_string())
} else {
Ok(*eval(ast, syms)?.clone())
}
}
pub const HELP_DOCSTRING: &str = "prints help text for a given symbol. Expects only one argument.";
pub fn help_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {