From 6daf0867df09768dd4c47a707a7cc024eeb3331c Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Fri, 10 Mar 2023 16:54:22 -0800 Subject: [PATCH] implementations for quote and eval --- Readme.org | 32 ++++++++++++++++++++++++++------ src/stl/decl.rs | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Readme.org b/Readme.org index f691b5c..d1f8514 100644 --- a/Readme.org +++ b/Readme.org @@ -301,23 +301,43 @@ This contains any executable target of this project. Notably the main shell file Note: this section will not show the status of each item unless you are viewing it with a proper orgmode viewer. Note: this section only tracks the state of incomplete TODO items. Having everything on here would be cluttered. -*** TODO Syntax improvements -**** WONTDO implicit single quote -**** TODO :symbol syntax -**** TODO Update Tests -**** TODO Update Makefile documentation *** TODO Quote function + (just needs tests and stl entries) *** TODO Eval function + (just needs tests and stl entries) +*** TODO list contains via circuit +*** TODO Lambda hack +BAD IDEAS +- lambda function can use illegal name parameter for symbol names, guaranteeing non collision in symbol table +- add some incrementing variable to avoid lambdas colliding with lambdas +- custom drop implementation for Ctr that only overrides Symbol, checks for illegal name conventions, and yeets from symtable + (how do we get the sym table into the drop impl) +- when repl loops, clear lambdas out of the symtable + (shit hack and will only work for very simple cases. highly not ideal) +GOOD IDEA +- could implement a new Ctr type to encapsulate function and args + - would need a new case in store for when bound to a var but honestly store should be rewritten + - would need a case in eval that mirrors the function call case + +DOCUMENTATION: +- let case for creating and applying a lambda +*** TODO Map function +- DOCUMENTATION + TEST: + apply a lambda to a list +*** TODO Reduce function *** TODO Input function *** TODO Lex function *** TODO Read function (Input + Lex) +*** TODO Caps function (list functions in table) +*** TODO Default prompt says " LAMBDA:" *** TODO Load (load a script) function Pull/Refactor the logic out of the configure functions. Optionally return a list of new variables and/or functions? Will need a concatenate function for tables *** TODO Main shell calls Load function on arg and exits +*** TODO Ship a relish-based stdlib *** TODO FINISH DOCUMENTATION -*** TODO Shell module +*** TODO Shell module- **** TODO only loadable via POSIX config var Overload Load function to call a binary too **** TODO arg processor because these are control flow diff --git a/src/stl/decl.rs b/src/stl/decl.rs index 735b81d..37ec731 100644 --- a/src/stl/decl.rs +++ b/src/stl/decl.rs @@ -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 { + 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 { + 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 {