-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/adam-mcdaniel/dune into arg…
…s-flatten
- Loading branch information
Showing
8 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "dune" | ||
version = "0.1.8" | ||
version = "0.1.9" | ||
authors = ["Adam McDaniel <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use super::fn_module::curry; | ||
use common_macros::b_tree_map; | ||
use dune::{Environment, Error, Expression}; | ||
|
||
fn split(args: Vec<Expression>, env: &mut Environment) -> Result<Expression, Error> { | ||
if args.len() != 2 { | ||
return Err(Error::CustomError(format!( | ||
"expected 2 arguments, got {}", | ||
args.len() | ||
))); | ||
} | ||
match (args[0].eval(env)?, args[1].eval(env)?) { | ||
( | ||
Expression::Symbol(x) | Expression::String(x), | ||
Expression::Symbol(y) | Expression::String(y), | ||
) => { | ||
let mut v = Vec::new(); | ||
for s in y.split(&x) { | ||
v.push(Expression::String(s.to_string())); | ||
} | ||
Ok(Expression::List(v)) | ||
} | ||
(a, b) => Err(Error::CustomError(format!( | ||
"expected string, got values {} and {}", | ||
a, b | ||
))), | ||
} | ||
} | ||
|
||
pub fn get() -> Expression { | ||
(b_tree_map! { | ||
String::from("isws") => Expression::builtin("isws", |args, env| { | ||
match args[0].eval(env)? { | ||
Expression::Symbol(x) | Expression::String(x) => { | ||
Ok(Expression::Boolean(x.chars().all(|c| c.is_whitespace()))) | ||
} | ||
otherwise => Err(Error::CustomError(format!( | ||
"expected string, got value {}", | ||
otherwise | ||
))), | ||
} | ||
}, "is this string whitespace?"), | ||
|
||
String::from("isalpha") => Expression::builtin("isalpha", |args, env| { | ||
match args[0].eval(env)? { | ||
Expression::Symbol(x) | Expression::String(x) => { | ||
Ok(Expression::Boolean(x.chars().all(|c| c.is_alphabetic()))) | ||
} | ||
otherwise => Err(Error::CustomError(format!( | ||
"expected string, got value {}", | ||
otherwise | ||
))), | ||
} | ||
}, "is this string alphabetic?"), | ||
|
||
String::from("isalphanumeric") => Expression::builtin("isalphanumeric", |args, env| { | ||
match args[0].eval(env)? { | ||
Expression::Symbol(x) | Expression::String(x) => { | ||
Ok(Expression::Boolean(x.chars().all(|c| c.is_alphanumeric()))) | ||
} | ||
otherwise => Err(Error::CustomError(format!( | ||
"expected string, got value {}", | ||
otherwise | ||
))), | ||
} | ||
}, "is this string alphanumeric?"), | ||
|
||
String::from("isnumeric") => Expression::builtin("isnumeric", |args, env| { | ||
match args[0].eval(env)? { | ||
Expression::Symbol(x) | Expression::String(x) => { | ||
Ok(Expression::Boolean(x.chars().all(|c| c.is_numeric()))) | ||
} | ||
otherwise => Err(Error::CustomError(format!( | ||
"expected string, got value {}", | ||
otherwise | ||
))), | ||
} | ||
}, "is this string numeric?"), | ||
|
||
String::from("split") => Expression::builtin("split", |args, env| { | ||
curry(Expression::builtin("", split, ""), 2, env)? | ||
.eval(env)? | ||
.apply(args) | ||
.eval(env) | ||
}, "split a string on a given character"), | ||
}) | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters