Skip to content

Commit

Permalink
Merge pull request #12 from co1emi11er2/Vectors
Browse files Browse the repository at this point in the history
Vectors
  • Loading branch information
co1emi11er2 authored Jul 2, 2024
2 parents 46e2232 + 4e26e6b commit 4b96230
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 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.2"
version = "0.3.3"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
2 changes: 1 addition & 1 deletion src/Handcalcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using MacroTools
using LaTeXStrings
using CodeTracking, Revise
using InteractiveUtils
import AbstractTrees: Leaves
import AbstractTrees: Leaves, PostOrderDFS
using PrecompileTools: @setup_workload, @compile_workload

export @handcalc, @handcalcs, @handfunc, multiline_latex, collect_exprs
Expand Down
8 changes: 8 additions & 0 deletions src/handcalc_marco.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ function _walk_expr(expr::Vector, math_syms)
count = 1
return ex
end
if Meta.isexpr(ex, :ref)
count = length(collect(PostOrderDFS(ex)))
return Expr(:$, ex)
end
if (ex isa Symbol) & (ex math_syms)
count = 1
return numeric_sub(ex)
Expand All @@ -122,6 +126,10 @@ function _walk_expr(expr::Expr, math_syms)
count -= 1
return ex
end
if Meta.isexpr(ex, :ref)
count = length(collect(PostOrderDFS(ex)))
return Expr(:$, ex)
end
if Meta.isexpr(ex, :.) # interpolates field args
count = length(ex.args) + 1
return Expr(:$, ex)
Expand Down
44 changes: 44 additions & 0 deletions test/handcalc_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,47 @@ calc2 = @handcalc begin x = (-b + sqrt(b^2 - 4*a*c))/(2*a) end
@test x == 2.0
@test calc2 == expected
# ***************************************************


# foo with args and kwargs
# ***************************************************
# ***************************************************
let
expected = L"$x = \frac{ - b + \sqrt{b^{2} - 4 \cdot a \cdot c}}{2 \cdot a} = \frac{ + 5 + \sqrt{\left( -5 \right)^{2} - 4 \cdot 2 \cdot 2}}{2 \cdot 2} = 2.0$"

function foo(x; y, z)
return x + y + z
end

x = 5
y = 3
z = 7

expected1 = L"$\mathrm{foo}\left( y, z, x \right) = \mathrm{foo}\left( 3, 7, 5 \right) = 15$"
calc1 = @handcalc foo(x; y, z)
@test calc1 == expected1

expected2 = L"$\mathrm{foo}\left( x; y = y, z = z \right) = \mathrm{foo}\left( 5; y = 3, z = 7 \right) = 15$"
calc2 = @handcalc foo(x; y=y, z=z)
@test calc2 == expected2

expected3 = L"$\mathrm{foo}\left( x, y = y, z = z \right) = \mathrm{foo}\left( 5, y = 3, z = 7 \right) = 15$"
calc3 = @handcalc foo(x, y=y, z=z)
@test calc3 == expected3

end
# ***************************************************


# array indexing
# ***************************************************
# ***************************************************
let
x = [1 2]

expected = L"$x\left[x\left[1\right]\right] + x\left[2\right] = 1 + 2 = 3$"
calc = @handcalc x[x[1]] + x[2]
@test calc == expected

end
# ***************************************************

4 comments on commit 4b96230

@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

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/110231

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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.3 -m "<description of version>" 4b962305eb18aba7719f3f09cb964f9d48185986
git push origin v0.3.3

@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 updated: JuliaRegistries/General/110231

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.3 -m "<description of version>" 4b962305eb18aba7719f3f09cb964f9d48185986
git push origin v0.3.3

Please sign in to comment.