thautwarm / MLStyle.jl

Julia functional programming infrastructures and metaprogramming facilities
https://thautwarm.github.io/MLStyle.jl/latest/
MIT License
404 stars 39 forks source link

Implement @tryswitch #132

Closed serenity4 closed 2 years ago

serenity4 commented 2 years ago

Implements @tryswitch as an extension to @switch where match failures are silent.

As mentioned in #131 we can move this implementation into a 3rd party library, but I think it is also convenient to have it alongside MLStyle.

codecov[bot] commented 2 years ago

Codecov Report

Merging #132 (d6b794e) into master (7bf8143) will increase coverage by 0.68%. The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #132      +/-   ##
==========================================
+ Coverage   81.94%   82.63%   +0.68%     
==========================================
  Files          26       26              
  Lines        1523     1589      +66     
==========================================
+ Hits         1248     1313      +65     
- Misses        275      276       +1     
Impacted Files Coverage Δ
src/MatchImpl.jl 91.78% <85.71%> (-0.04%) :arrow_down:
src/AbstractPatterns/impl/RedyFlavoured.jl 91.75% <0.00%> (-0.10%) :arrow_down:
src/MatchCore.jl 5.50% <0.00%> (-0.06%) :arrow_down:
src/DeprecationUtils.jl 100.00% <0.00%> (ø)
src/StandardPatterns/WhenCases.jl 100.00% <0.00%> (ø)
src/AbstractPatterns/AbstractPatterns.jl 100.00% <0.00%> (ø)
src/AbstractPatterns/CaseMerge.jl 98.52% <0.00%> (+0.14%) :arrow_up:
src/Pervasives.jl 92.30% <0.00%> (+0.30%) :arrow_up:
src/Modules/AST.jl 84.78% <0.00%> (+0.33%) :arrow_up:
... and 9 more

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 7bf8143...d6b794e. Read the comment docs.

Roger-luo commented 2 years ago

since the PR is submitted here, maybe just have it in MLStyle? Expronicon is for meta-programming not the general case of pattern matching.

thautwarm commented 2 years ago

@Roger-luo A minor issue here is the implementation reuses @switch macro, hence the macro expands twice. Such operation can produce bad error messages when get used extensively.

thautwarm commented 2 years ago

I'd merge this now. Changes can be applied later. Thanks @serenity4 !

serenity4 commented 2 years ago

@Roger-luo A minor issue here is the implementation reuses @switch macro, hence the macro expands twice. Such operation can produce bad error messages when get used extensively.

Ah, then we can just reuse the few lines of code for @switch (gen_switch and init_cfg). I thought reusing @switch would make it cleaner in terms of implementation. What is the problem with error messages? From a few local tests I couldn't see any issues with it.