From 5f5bcca7fb985f354c778b4795470d82704db074 Mon Sep 17 00:00:00 2001 From: co1emi11er2 Date: Tue, 2 Jul 2024 13:22:34 -0500 Subject: [PATCH 1/4] Fixed bug with not_funcs --- docs/src/index.md | 13 ++++++++++--- src/Handcalcs.jl | 4 +++- src/handcalc_marco.jl | 4 ++++ test/default_h_kwargs.jl | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index d18c689..015aca1 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -114,18 +114,25 @@ x = 0 y = sin(x) z = cos(x) I_x, I_y = TestHandcalcFunctions.calc_Is(5, 15) -end not_funcs = [sin cos] +end not_funcs = [:sin :cos] ``` In the above example `sin` and `cos` were passed over and calc_Is was not. As you can see, the calc_Is function was a function that called other functions, and the @handcalcs macro continued to step into each function to unroll all expressions. Please see below for a list of the current functions that are passed over automatically. Please submit a pull request if you would like to add more generic math functions that I have left out. -``` +```julia const math_syms = [ :*, :/, :^, :+, :-, :%, :.*, :./, :.^, :.+, :.-, :.%, :<, :>, Symbol(==), :<=, :>=, :.<, :.>, :.==, :.<=, :.>=, - :sqrt, :sin, :cos, :tan] + :sqrt, :sin, :cos, :tan, :sum, + :cumsum, :max, :min, :exp] +``` + +If you want to add functions to your specific project, you can do the following: + +```@example main +set_handcalcs(not_funcs = [:foo :bar :baz]) ``` Current Limitations for `@handcalcs` diff --git a/src/Handcalcs.jl b/src/Handcalcs.jl index 8f7e927..39792c5 100644 --- a/src/Handcalcs.jl +++ b/src/Handcalcs.jl @@ -27,7 +27,9 @@ const math_syms = [ :.*, :./, :.^, :.+, :.-, :.%, :<, :>, Symbol(==), :<=, :>=, :.<, :.>, :.==, :.<=, :.>=, - :sqrt, :sin, :cos, :tan] + :sqrt, :sin, :cos, :tan, :sum, + :cumsum, :max, :min, :exp] + const h_syms = [:cols, :spa, :h_env, :len] include("default_h_kwargs.jl") diff --git a/src/handcalc_marco.jl b/src/handcalc_marco.jl index 3c64ba6..8772144 100644 --- a/src/handcalc_marco.jl +++ b/src/handcalc_marco.jl @@ -161,6 +161,10 @@ end function check_not_funcs(f, kwargs) not_funcs = find_not_funcs(kwargs) not_funcs = typeof(not_funcs) == Symbol ? [not_funcs] : not_funcs + defaults = get(default_h_kwargs, :not_funcs, []) + if defaults != [] + push!(not_funcs, defaults...) + end return f ∉ not_funcs end diff --git a/test/default_h_kwargs.jl b/test/default_h_kwargs.jl index a0ee0c4..fba3d5e 100644 --- a/test/default_h_kwargs.jl +++ b/test/default_h_kwargs.jl @@ -31,3 +31,17 @@ calc = @handcalcs begin end @test calc == expected reset_handcalcs() + + +# use set_handcalcs for not_funcs +# *************************************************** +# *************************************************** +set_handcalcs(not_funcs = [:calc_Ix]) + +expected = L"$\begin{aligned} +Ix &= \mathrm{calc}_{Ix}\left( 5, 15 \right) = 1406.25 +\end{aligned}$" + +calc = @handcalcs Ix = calc_Ix(5, 15) +@test calc == expected +reset_handcalcs() From 9acd02d977ab40a7789a56f15ee75e6899641eb2 Mon Sep 17 00:00:00 2001 From: co1emi11er2 Date: Tue, 2 Jul 2024 13:34:45 -0500 Subject: [PATCH 2/4] update math_syms --- src/Handcalcs.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Handcalcs.jl b/src/Handcalcs.jl index 39792c5..f2dad51 100644 --- a/src/Handcalcs.jl +++ b/src/Handcalcs.jl @@ -28,7 +28,8 @@ const math_syms = [ :<, :>, Symbol(==), :<=, :>=, :.<, :.>, :.==, :.<=, :.>=, :sqrt, :sin, :cos, :tan, :sum, - :cumsum, :max, :min, :exp] + :cumsum, :max, :min, :exp, :log, + :log10] const h_syms = [:cols, :spa, :h_env, :len] From 7effca6c150bb89499ffd4809e14b8670f8c104f Mon Sep 17 00:00:00 2001 From: co1emi11er2 Date: Tue, 2 Jul 2024 13:35:16 -0500 Subject: [PATCH 3/4] Update index.md --- docs/src/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index 015aca1..0fcabfe 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -126,7 +126,8 @@ const math_syms = [ :<, :>, Symbol(==), :<=, :>=, :.<, :.>, :.==, :.<=, :.>=, :sqrt, :sin, :cos, :tan, :sum, - :cumsum, :max, :min, :exp] + :cumsum, :max, :min, :exp, :log, + :log10] ``` If you want to add functions to your specific project, you can do the following: From abfc77da3c5b062f974b5f102e9f363810a71d1e Mon Sep 17 00:00:00 2001 From: co1emi11er2 Date: Tue, 2 Jul 2024 13:35:56 -0500 Subject: [PATCH 4/4] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a94c10a..4a0e93b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Handcalcs" uuid = "e8a07092-c156-4455-ab8e-ed8bc81edefb" authors = ["Cole Miller"] -version = "0.3.3" +version = "0.3.4" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"