Compare commits

...
Author SHA1 Message Date
f1c6073708
feat: add ln function
this one is easier than log or root, because it only takes one arg
2026-10-06 11:51:04 -07:00
e59f928192
refactor: simplify input logic 2026-10-04 16:45:48 -07:00
4 changed files with 12 additions and 5 deletions

View file

@ -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}"),

View file

@ -52,6 +52,8 @@ fn collapse_toplevel(nodes: &mut Vec<Node>, 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(),

View file

@ -76,6 +76,8 @@ pub enum Operator {
pub enum Function {
Sqrt,
Ln,
Sine,
ArcSine,
Cosine,

View file

@ -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),