JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
545 stars 114 forks source link

add capture macro #343

Closed willow-ahrens closed 3 years ago

willow-ahrens commented 3 years ago

This commit adds a simple macro for simply matching terms and injecting the matches into the current scope, as described in #342. The macro returns true or false depending on whether the pattern was matched.

YingboMa commented 3 years ago

Do you mind to add a few tests?

shashi commented 3 years ago

Nice! and a doc string would be great too.

willow-ahrens commented 3 years ago

Alright, docstring and tests added!

willow-ahrens commented 3 years ago

Alright! Thanks @MasonProtter for the suggestions! I've resolved everything except for the potential macrotools name collision. It might be easiest to simply leave the macro un-exported, but I'll wait for your (or another) opinion on the matter.

willow-ahrens commented 3 years ago

The version has been bumped to 16.0 because this is a breaking change.

codecov-commenter commented 3 years ago

Codecov Report

Merging #343 (162d419) into master (609f7a2) will decrease coverage by 0.18%. The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #343      +/-   ##
==========================================
- Coverage   83.80%   83.61%   -0.19%     
==========================================
  Files          12       12              
  Lines        1451     1465      +14     
==========================================
+ Hits         1216     1225       +9     
- Misses        235      240       +5     
Impacted Files Coverage Δ
src/rule.jl 84.44% <69.23%> (-2.34%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 609f7a2...162d419. Read the comment docs.

shashi commented 3 years ago

I don't see any breaking changes though? What's something that doesn't work that used to work?

willow-ahrens commented 3 years ago

using MacroTools; using SymbolicUtils used to work, now results in name collision because we export @capture. If you don't want me to bump the version I can set it back.

shashi commented 3 years ago

Ah ok!

YingboMa commented 3 years ago

We really shouldn't export @capture

[ Info: Precompiling ModelingToolkit [961ee093-0014-501f-94e3-6117800e7a78]
WARNING: both MacroTools and SymbolicUtils export "@capture"; uses of it in module Symbolics must be qualified
WARNING: both Symbolics and MacroTools export "@capture"; uses of it in module ModelingToolkit must be qualified
willow-ahrens commented 3 years ago

Perhaps that should go in a separate PR? Unless you'd like me to push a quick fix to this branch, which I'm willing to do.

YingboMa commented 3 years ago

Yeah, let's make a new PR and a new breaking release.