mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-31 17:09:13 +01:00
Added 'help' command in the REPL
This commit is contained in:
parent
9cacb0c57a
commit
0d4398e4a5
71
kalk_cli/help.txt
Normal file
71
kalk_cli/help.txt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
Overview of features
|
||||||
|
Operators: +, -, *, /, !, %
|
||||||
|
Groups: (), ⌈⌉, ⌋⌊
|
||||||
|
Pre-defined functions and constants
|
||||||
|
User-defined functions and variables
|
||||||
|
User-defined units (experimental)
|
||||||
|
Understands fairly ambiguous syntax. Eg. 2sin50 + 2xy
|
||||||
|
Syntax highlighting
|
||||||
|
Completion for special symbols on tab
|
||||||
|
Sum functions
|
||||||
|
|
||||||
|
Operators
|
||||||
|
+, -, *, /
|
||||||
|
! Factorial, eg. 5! gives 120
|
||||||
|
% Percent, eg. 5% gives 0.05, 10 + 50% gives 15
|
||||||
|
% Modulus (remainder), eg. 23 % 3 gives 2
|
||||||
|
|
||||||
|
Completion for special symbols
|
||||||
|
You can type special symbols (such as √) by typing the normal function or constant name and pressing tab.
|
||||||
|
|
||||||
|
sqrt becomes √
|
||||||
|
deg becomes °
|
||||||
|
pi becomes π
|
||||||
|
sum becomes Σ()
|
||||||
|
tau becomes τ
|
||||||
|
phi becomes ϕ
|
||||||
|
floor becomes ⌊⌋
|
||||||
|
ceil becomes ⌈⌉
|
||||||
|
gamma becomes Γ
|
||||||
|
( becomes ()
|
||||||
|
|
||||||
|
Variables
|
||||||
|
Variables are defined with the following syntax: name = value
|
||||||
|
Example: x = 3/4
|
||||||
|
|
||||||
|
Functions
|
||||||
|
Functions are defined with the following syntax: name(param1, param2, etc.) = value
|
||||||
|
Examples: f(x) = 2x+3; A(x, y) = (xy)/2
|
||||||
|
They are used like this: name(arg1, arg2, etc.)
|
||||||
|
Example: f(3) + 3 A(2, 3)
|
||||||
|
|
||||||
|
Predefined functions
|
||||||
|
sin, cos, tan, cot, cosec, sec
|
||||||
|
sinh, cosh, tanh, coth, cosech, sech
|
||||||
|
asin, acos, atan, acot, acosec, asec
|
||||||
|
asinh, acosh, atanh, acoth, acosech, asech
|
||||||
|
abs, ceil or ⌈⌉, floor or ⌊⌋, frac, round, trunc
|
||||||
|
sqrt or √, cbrt, exp, log, ln
|
||||||
|
gamma or Γ
|
||||||
|
asinh, acosh, atanh, acoth, acosech, asech
|
||||||
|
min, max, hyp
|
||||||
|
log Eg. log(1000, 10) is the same as log10(1000)
|
||||||
|
root Eg. root(16, 3) is the same as 3√16
|
||||||
|
sum Eg. sum(1, 4, 2n), example below
|
||||||
|
|
||||||
|
Sum function
|
||||||
|
The sum function lets you sum an expression with an incrementing variable.
|
||||||
|
It takes three arguments: start value, end value, and expression.
|
||||||
|
If you press tab after typing out "sum", it will be replaced with a sigma symbol.
|
||||||
|
The expression is what will be summed, and will be able to use the "n" variable,
|
||||||
|
which represents the current value between the start value and the end value.
|
||||||
|
The value of "n" increments.
|
||||||
|
Example: sum(1, 4, 2n) will be the same as 2*1 + 2*2 + 2*3 + 2*4 = 20
|
||||||
|
This can for example be used to calculate e: Σ(0, 10000, 1/n!) = 2.7182818284590455
|
||||||
|
More precision can be gotten by changing the "--precision" flag. Run `kalk --help` for more info.
|
||||||
|
|
||||||
|
Constants
|
||||||
|
pi or π = 3.14159265
|
||||||
|
e = 2.71828182
|
||||||
|
tau or τ = 6.2831853
|
||||||
|
phi or ϕ = 1.61803398
|
@ -49,10 +49,16 @@ fn eval_repl(parser: &mut parser::Context, input: &str, precision: u32) {
|
|||||||
"" => eprint!(""),
|
"" => eprint!(""),
|
||||||
"clear" => print!("\x1B[2J"),
|
"clear" => print!("\x1B[2J"),
|
||||||
"exit" => process::exit(0),
|
"exit" => process::exit(0),
|
||||||
|
"help" => print_cli_help(),
|
||||||
_ => output::eval(parser, input, precision),
|
_ => output::eval(parser, input, precision),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_cli_help() {
|
||||||
|
let help_text = include_str!("../help.txt");
|
||||||
|
println!("{}", help_text);
|
||||||
|
}
|
||||||
|
|
||||||
struct LineHighlighter {}
|
struct LineHighlighter {}
|
||||||
|
|
||||||
impl Highlighter for LineHighlighter {
|
impl Highlighter for LineHighlighter {
|
||||||
|
Loading…
Reference in New Issue
Block a user