From 56b83c2ee488dc9975b2702d8669dac776d7ed32 Mon Sep 17 00:00:00 2001 From: Xavier L'Heureux <xavier.lheureux@icloud.com> Date: Mon, 22 Jul 2019 16:58:01 -0400 Subject: [PATCH] improv!: Rename calc builtin to math to avoid conflict with GNU Fix #542 --- manual/src/builtins.md | 10 +++++----- manual/src/expansions/04-arithmetic.md | 2 +- src/lib/builtins/{calc.rs => math.rs} | 12 ++++++------ src/lib/builtins/mod.rs | 8 ++++---- src/lib/parser/pipelines.rs | 4 ++-- tests/fn.ion | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) rename src/lib/builtins/{calc.rs => math.rs} (91%) diff --git a/manual/src/builtins.md b/manual/src/builtins.md index 543b69e5..289d4b07 100644 --- a/manual/src/builtins.md +++ b/manual/src/builtins.md @@ -20,11 +20,11 @@ DESCRIPTION Returns true if the value given to it is equal to '1' or 'true'. ``` -## calc - Floating-point calculator +## math - Floating-point calculator ```txt SYNOPSIS - calc [EXPRESSION] + math [EXPRESSION] DESCRIPTION Evaluates arithmetic expressions @@ -48,10 +48,10 @@ NOTATIONS EXAMPLES Add two plus two in infix notation - calc 2+2 + math 2+2 Add two plus two in polish notation - calc + 2 2 + math + 2 2 AUTHOR Written by Hunter Goldstein. @@ -604,4 +604,4 @@ SYNOPSIS DESCRIPTION The which utility takes a list of command names and searches for the alias/builtin/function/executable that would be executed if you ran that command. -``` \ No newline at end of file +``` diff --git a/manual/src/expansions/04-arithmetic.md b/manual/src/expansions/04-arithmetic.md index 50fd94f5..4dfbf90a 100644 --- a/manual/src/expansions/04-arithmetic.md +++ b/manual/src/expansions/04-arithmetic.md @@ -2,7 +2,7 @@ We've exported our arithmetic logic into a separate crate [calculate](https://crates.io/crates/calculate). We use this library for both our `calc` builtin, -and for parsing arithmetic expansions. Use `calc` if you want a REPL for arithmetic, else use +and for parsing arithmetic expansions. Use `math` if you want a REPL for arithmetic, else use arithmetic expansions (`$((a + b))`) if you want the result inlined. Variables may be passed into arithmetic expansions without the **$** sigil, as it is automatically inferred that text references string variables. Supported operators are as below: diff --git a/src/lib/builtins/calc.rs b/src/lib/builtins/math.rs similarity index 91% rename from src/lib/builtins/calc.rs rename to src/lib/builtins/math.rs index bc11a9a4..7b9ec595 100644 --- a/src/lib/builtins/calc.rs +++ b/src/lib/builtins/math.rs @@ -5,7 +5,7 @@ use calc::{eval, eval_polish, CalcError, Value}; use liner::Context; use std::io::{self, Read}; -const REPL_GUIDE: &str = r#"ion-calc +const REPL_GUIDE: &str = r#"Ion's integrated calculator Type in expressions to have them evaluated. Type "help" for help."#; @@ -20,7 +20,7 @@ fn calc_or_polish_calc(args: &str) -> Result<Value, CalcError> { desc = "Floating-point calculator", man = " SYNOPSIS - calc [EXPRESSION] + math [EXPRESSION] DESCRIPTION Evaluates arithmetic expressions @@ -44,15 +44,15 @@ NOTATIONS EXAMPLES Add two plus two in infix notation - calc 2+2 + math 2+2 Add two plus two in polish notation - calc + 2 2 + math + 2 2 AUTHOR Written by Hunter Goldstein." )] -pub fn calc(args: &[crate::types::Str], _: &mut crate::Shell<'_>) -> Status { +pub fn math(args: &[crate::types::Str], _: &mut crate::Shell<'_>) -> Status { if args.get(1).is_some() { let result = calc_or_polish_calc(&args[1..].join(" ")); match result { @@ -67,7 +67,7 @@ pub fn calc(args: &[crate::types::Str], _: &mut crate::Shell<'_>) -> Status { let mut context = Context::new(); loop { match context - .read_line("ion-calc: ", None, &mut EmptyCompleter) + .read_line("ion-math: ", None, &mut EmptyCompleter) .as_ref() .map(AsRef::as_ref) { diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index a5d452f5..db3b22cf 100644 --- a/src/lib/builtins/mod.rs +++ b/src/lib/builtins/mod.rs @@ -1,7 +1,6 @@ /// helpers for creating help pub mod man_pages; -mod calc; mod command_info; mod conditionals; mod echo; @@ -10,6 +9,7 @@ mod functions; mod helpers; mod is; mod job_control; +mod math; mod random; mod set; mod source; @@ -18,7 +18,6 @@ mod test; mod variables; pub use self::{ - calc::builtin_calc, command_info::builtin_which, conditionals::{builtin_contains, builtin_ends_with, builtin_starts_with}, echo::builtin_echo, @@ -27,6 +26,7 @@ pub use self::{ helpers::Status, is::builtin_is, man_pages::check_help, + math::builtin_math, set::builtin_set, source::builtin_source, status::builtin_status, @@ -196,11 +196,11 @@ impl<'a> BuiltinMap<'a> { /// Utilities to test values /// - /// Contains `bool`, `calc`, `eq`, `is`, `true`, `false`, `starts-with`, `ends-with`, + /// Contains `bool`, `math`, `eq`, `is`, `true`, `false`, `starts-with`, `ends-with`, /// `contains`, `matches`, `random` pub fn with_values_tests(&mut self) -> &mut Self { self.add("bool", &builtin_bool, "If the value is '1' or 'true', return 0 exit status") - .add("calc", &builtin_calc, "Calculate a mathematical expression") + .add("math", &builtin_math, "Calculate a mathematical expression") .add("eq", &builtin_is, "Simple alternative to == and !=") .add("is", &builtin_is, "Simple alternative to == and !=") .add("true", &builtin_true_, "Do nothing, successfully") diff --git a/src/lib/parser/pipelines.rs b/src/lib/parser/pipelines.rs index 16572c4b..8f24d92f 100644 --- a/src/lib/parser/pipelines.rs +++ b/src/lib/parser/pipelines.rs @@ -987,10 +987,10 @@ mod tests { #[test] fn herestring() { - let input = "calc <<< $(cat math.txt)"; + let input = "math <<< $(cat math.txt)"; let expected = Pipeline { items: vec![PipeItem { - job: Job::new(args!["calc"], RedirectFrom::None, None), + job: Job::new(args!["math"], RedirectFrom::None, None), inputs: vec![Input::HereString("$(cat math.txt)".into())], outputs: vec![], diff --git a/tests/fn.ion b/tests/fn.ion index c4db566e..da36a247 100644 --- a/tests/fn.ion +++ b/tests/fn.ion @@ -15,7 +15,7 @@ end another_test fn square n:int - calc $n \* $n + math $n \* $n end for num in 1 2 3 4 5 a 1.5 -- GitLab