From e59f9281927fa12df9d06abd73c5c4164528704c Mon Sep 17 00:00:00 2001 From: electria Date: Sun, 4 Oct 2026 16:45:48 -0700 Subject: [PATCH 1/2] refactor: simplify input logic --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc19a05..c3349d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,14 +7,15 @@ use std::{ use tylc as lib; fn main() -> ExitCode { - let input = match env::args().skip(1).rev().reduce(|x, a| a + &x) { - Some(s) => s, - None => { + let input = env::args() + .skip(1) + .rev() + .reduce(|x, a| a + &x) + .unwrap_or_else(|| { let mut buf = String::new(); io::stdin().read_to_string(&mut buf).unwrap(); buf - } - }; + }); match lib::formatting::pretty_eval(input, 10) { Ok(s) => println!("{s}"), From f1c6073708dcfa9d734960832019a7606de348c8 Mon Sep 17 00:00:00 2001 From: electria Date: Tue, 6 Oct 2026 11:51:04 -0700 Subject: [PATCH 2/2] feat: add ln function this one is easier than log or root, because it only takes one arg --- src/nodes/eval.rs | 2 ++ src/nodes/mod.rs | 2 ++ src/nodes/parse.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/nodes/eval.rs b/src/nodes/eval.rs index 27d6907..ea06c2b 100644 --- a/src/nodes/eval.rs +++ b/src/nodes/eval.rs @@ -52,6 +52,8 @@ fn collapse_toplevel(nodes: &mut Vec, mut end: usize) -> Result<(), Error> Node::Number(n) => match variant { Function::Sqrt => n.sqrt_mut(), + Function::Ln => n.ln_mut(), + Function::Sine => n.sin_mut(), Function::ArcSine => n.asin_mut(), Function::Cosine => n.cos_mut(), diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index d8e05d9..dbc5461 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -76,6 +76,8 @@ pub enum Operator { pub enum Function { Sqrt, + Ln, + Sine, ArcSine, Cosine, diff --git a/src/nodes/parse.rs b/src/nodes/parse.rs index 4a20221..50d0f13 100644 --- a/src/nodes/parse.rs +++ b/src/nodes/parse.rs @@ -37,6 +37,8 @@ impl FromStr for Function { match s { "sqrt" => Ok(Self::Sqrt), + "ln" => Ok(Self::Ln), + "sin" => Ok(Self::Sine), "asin" => Ok(Self::ArcSine), "cos" => Ok(Self::Cosine),