moved lamm to it's own repository
This commit is contained in:
28
src/commands/eval.rs
Normal file
28
src/commands/eval.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use crate::common::{Context, Error};
|
||||
use std::io::Cursor;
|
||||
|
||||
/// Evaluates a Lamm program
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn eval(ctx: Context<'_>,
|
||||
#[rest]
|
||||
expr: String) -> Result<(), Error>
|
||||
{
|
||||
let values = lamm::evaluate(Cursor::new(expr));
|
||||
|
||||
let output = values.fold(Ok(String::new()), |acc, v| {
|
||||
if acc.is_err() {
|
||||
return acc;
|
||||
};
|
||||
|
||||
let x = acc.unwrap();
|
||||
|
||||
match v {
|
||||
Ok(v) => Ok(format!("{x}\n{v}")),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
});
|
||||
|
||||
ctx.reply(output?).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user