Skip to content

Commit

Permalink
Merge pull request #14 from co1emi11er2/not_funcs
Browse files Browse the repository at this point in the history
Not funcs
  • Loading branch information
co1emi11er2 authored Jul 2, 2024
2 parents 4b96230 + abfc77d commit 10ee409
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 11 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,26 @@ 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, :log,
:log10]
```

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`
Expand Down
5 changes: 4 additions & 1 deletion src/Handcalcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const math_syms = [
:.*, :./, :.^, :.+, :.-, :.%,
:<, :>, Symbol(==), :<=, :>=,
:.<, :.>, :.==, :.<=, :.>=,
:sqrt, :sin, :cos, :tan]
:sqrt, :sin, :cos, :tan, :sum,
:cumsum, :max, :min, :exp, :log,
:log10]

const h_syms = [:cols, :spa, :h_env, :len]

include("default_h_kwargs.jl")
Expand Down
4 changes: 4 additions & 0 deletions src/handcalc_marco.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions test/default_h_kwargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

2 comments on commit 10ee409

@co1emi11er2
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Bug Fixes

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110259

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.4 -m "<description of version>" 10ee409947596110f9eeb9953ca045742c4cf97e
git push origin v0.3.4

Please sign in to comment.