Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Docs suggestions #114

Merged
merged 29 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7ac2b5b
Update how.md
caseykneale Mar 13, 2021
3f567f6
Update what.md
caseykneale Mar 13, 2021
e4b8bb0
Update benchmark.md
caseykneale Mar 13, 2021
5c160fe
Update capture.md
caseykneale Mar 13, 2021
24db571
Update query-lang.md
caseykneale Mar 13, 2021
04a03fc
Update adt.md
caseykneale Mar 13, 2021
102c894
Update pattern.md
caseykneale Mar 13, 2021
17e2102
Update pattern.md
caseykneale Mar 13, 2021
fb2d4e2
Update switch.md
caseykneale Mar 13, 2021
d21c4d5
Update when.md
caseykneale Mar 13, 2021
d484a9c
Update ast.md
caseykneale Mar 13, 2021
246999c
Update what.md
caseykneale Mar 13, 2021
c2b4053
Update docs/benchmark.md
caseykneale Mar 15, 2021
187634e
Update docs/benchmark.md
caseykneale Mar 15, 2021
07e5c07
Update docs/benchmark.md
caseykneale Mar 15, 2021
0c3ba40
Update docs/syntax/adt.md
caseykneale Mar 15, 2021
622a5f5
Update docs/what.md
caseykneale Mar 15, 2021
54af9f6
Update docs/syntax/pattern.md
caseykneale Mar 15, 2021
de44e6b
Update docs/syntax/pattern.md
caseykneale Mar 15, 2021
74a4295
Update docs/syntax/pattern.md
caseykneale Mar 15, 2021
3baed72
Update docs/syntax/switch.md
caseykneale Mar 15, 2021
a3cf985
Update docs/syntax/switch.md
caseykneale Mar 15, 2021
d4c8f95
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
68c2fb6
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
50c3005
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
d3c88e0
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
163df2d
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
22c275e
Update docs/tutorials/query-lang.md
caseykneale Mar 15, 2021
866e3bf
Update what.md
caseykneale Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Benchmark

In terms of data shape validation, MLStyle can be strictly faster than even a carefully optimized handwritten code.
In terms of data shape validation, MLStyle can often be faster than carefully optimized handwritten code.

All benchmark scripts are provided in the directory [Matrix-Benchmark](https://github.com/thautwarm/MLStyle.jl/blob/master/matrix-benchmark).
All of the scripts for the benchmarks are provided in the directory: [Matrix-Benchmark](https://github.com/thautwarm/MLStyle.jl/blob/master/matrix-benchmark).

To run these cross-implementation benchmarks, some extra dependencies should be installed:
To run these cross-implementation benchmarks, some extra Julia packages should be installed:
caseykneale marked this conversation as resolved.
Show resolved Hide resolved

- `(v1.4) pkg> add Gadfly MacroTools Rematch Match BenchmarkTools StatsBase Statistics ArgParse DataFrames`.

Expand All @@ -16,11 +16,11 @@ The benchmarks presented here are made by Julia **v1.4** on **Windows 10(64 bit)

*Benchmark results for other platforms and Julia versions are welcome to get accepted as a pull request, if you figure out a better way to organize the files and their presentations in this README.*

(*We rule out the benchmarks of the space use, it's considered unnecessary as the cost are always zero which is not only for MLStyle*)
(*We leave out the benchmarks of the space used. That should be considered unnecessary as the costs are always zero. *)

On the x-axis, after the name of test-case is the least time-consuming run's index in units of `ns`.

The y-label is the ratio of the implementation's time cost to that of the least time-consuming.
The y-axis is the ratio of the implementation's time cost, made relative to that of the least time-consuming.

The benchmark results in dataframe format are available at [this directory](https://github.com/thautwarm/MLStyle.jl/tree/master/stats).

Expand Down Expand Up @@ -58,4 +58,4 @@ The benchmark results in dataframe format are available at [this directory](http

- code: [matrix-benchmark/bench-vs-match.jl](https://github.com/thautwarm/MLStyle.jl/blob/master/matrix-benchmark/bench-vs-match.jl)

[![matrix-benchmark/bench-versus-match.jl](https://raw.githubusercontent.com/thautwarm/MLStyle.jl/master/stats/bench-versus-match.svg)](https://github.com/thautwarm/MLStyle.jl/blob/master/stats/bench-vs-match.txt)
[![matrix-benchmark/bench-versus-match.jl](https://raw.githubusercontent.com/thautwarm/MLStyle.jl/master/stats/bench-versus-match.svg)](https://github.com/thautwarm/MLStyle.jl/blob/master/stats/bench-vs-match.txt)
2 changes: 1 addition & 1 deletion docs/how.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

For installation, open the package manager mode in the Julia REPL and `add MLStyle`.

For more examples or tutorials, see [this project](https://github.com/thautwarm/MLStyle-Playground) which will be frequently updated to present some interesting uses of MLStyle.jl.
For more examples or tutorials, see [the MLStyle-Playground project](https://github.com/thautwarm/MLStyle-Playground). This project will be frequently updated to demonstrate some interesting uses of MLStyle.jl.
6 changes: 3 additions & 3 deletions docs/modules/ast.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MLStyle.Modules.AST
@matchast
---------------------

- Description: Similar to `@match`, but focus on AST matching. No need to quote patterns with `quote ... end` or `:(...)`.
- Description: Similar to `@match`, but the focus is on AST matching. There is no need to quote patterns with `quote ... end` or `:(...)`.
- Usage: `@matchast ast_to_match (begin cases... end)`
- Examples:

Expand Down Expand Up @@ -44,7 +44,7 @@ Dict{Symbol,Dict}(:s1 => Dict{Any,Any}(),:s2 => Dict{Symbol,Dict{Any,Any}}(:s1 =
@capture
-------------------

- Description: Similar to `MacroTools.@capture`, but provided with a more regex-flavored matching.
- Description: Similar to `MacroTools.@capture`, but provides a more regex-flavored matching.

- Usage: `@capture template input_ast`, note that `template` is purely static and cannot be a variable from current context.

Expand Down Expand Up @@ -73,4 +73,4 @@ outputs
│ :a => :a
│ :b => :b
└ :stmts => Any[:(#= REPL[8]:1 =#), :(a + b)]
```
```
4 changes: 2 additions & 2 deletions docs/syntax/adt.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ using MLStyle
end
```

Above codes makes a clarified description about Arithmetic operations and provides a corresponding implementation.
The above code makes a clear description about Arithmetic operations and provides a corresponding implementation.

If you want to transpile above ADTs to some specific language, there is a clear step:

Expand Down Expand Up @@ -137,7 +137,7 @@ About Type Parameters

`where` is used for type parameter introduction.

Following 2 patterns are equivalent:
The following 2 patterns are equivalent:
```julia
A{T1...}(T2...) where {T3...}
A{T1...}(T2...) :: A{T1...} where {T3...}
Expand Down
20 changes: 10 additions & 10 deletions docs/syntax/pattern.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Patterns
Pattern Matching
=======================

Patterns provide convenient ways to manipulate data. The basic syntax for pattern matching with MLStyle is of the form
Pattern matching provides convenient ways to manipulate data. The basic syntax for pattern matching with MLStyle is of the form
```julia
@match data begin
pattern1 => result1
Expand All @@ -10,7 +10,7 @@ Patterns provide convenient ways to manipulate data. The basic syntax for patter
patternn => resultn
end
```
MLStyle will first test if `data` is matched by `pattern1` and if it does match, return `result1`. If `pattern1` does not match, then MLStyle moves on to the next pattern. If no pattern in the list matches `data`, an error is thrown.
MLStyle will first test if `data` is matched by `pattern1` and if it does match, return `result1`. If `pattern1` does not match, then MLStyle moves on to the next pattern in sequence. If no pattern in the list matches `data`, an error is thrown.

In version 0.4.1 and newer, if you only have a single pattern you may instead write
```julia
Expand All @@ -32,7 +32,7 @@ julia> @match 10 begin
end
"right!"
```
All literal data introduced with Julia syntax could be matched by literal patterns.
All literal data introduced with Julia syntax can be matched by literal patterns.

However, note that the equality is strict for primitive types(`Int8-64`, `UInt8-64`, `Bool`, etc.) and singleton types(`struct Data end; Data()`).

Expand Down Expand Up @@ -82,10 +82,10 @@ julia> @match 1.0 begin
```

Unlike most of ML languages or other libraries who only permit guards in the end of a case clause,
MLStyle allows you to put guards anywhere during matching.
MLStyle.jl allows you to put guards anywhere during matching.

However, remember, due to some Julia optimization details, even if the guards can be put
in the middle of a matching process, still you'd better postpone it to the end of matching, for better performance.
in the middle of a matching process, it is still better to postpone it until the end of matching sequence. This allows for better performance.

Sometimes, in practice, you might want to introduce type variables into the scope, in this case use `where` clause, and see [Advanced Type Patterns](#advanced-type-patterns) for more details.

Expand Down Expand Up @@ -113,7 +113,7 @@ julia> @match (1, 2) begin
true
```

Destructuring Tuple Array and Dict Patterns
Destructuring Tuples, Arrays, and Dictionaries with Pattern Matching
---------------------

- Tuple Patterns
Expand Down Expand Up @@ -163,7 +163,7 @@ julia> @match dict begin
7
```

Note that, due to the lack of an operation for distinguishing `nothing` from "key not found" in Julia's standard library, the dictionary pattern has a little overhead. Things will get solved after [Julia#34821](https://github.com/JuliaLang/julia/pull/34821) gets done.
Note that, due to the lack of an operation for distinguishing `nothing` from "key not found" in Julia's standard library, the dictionary pattern has a little overhead. This will be resolved after [Julia#34821](https://github.com/JuliaLang/julia/pull/34821) is completed.

**P.S**: MLStyle will not refer an external package to solve this issue, as MLStyle is generating "runtime support free" code, which means that any code generated by MLStyle itself depends only on Stdlib. This feature allows MLStyle to be introduced as a dependency only in development, instead of being distributed together to downstream codes.

Expand Down Expand Up @@ -695,7 +695,7 @@ end # true

The pattern `quote .. end` is equivalent to `:(begin ... end)`.

Additionally, you can use any other patterns simultaneously when matching asts. In fact, there're regular patterns inside a `$` expression of your ast pattern.
Additionally, you can use any other patterns simultaneously when matching ASTs. In fact, there are regular patterns inside a `$` expression of your AST pattern.

A more complex example presented here might help with your comprehension about this:

Expand Down Expand Up @@ -747,7 +747,7 @@ end
# :app_arg => :d
```

Here is several articles about Ast Patterns.
If you are interested, here are several useful articles about AST Patterns:

- [A Modern Way to Manipulate ASTs](https://www.reddit.com/r/Julia/comments/ap4xwr/mlstylejl_a_modern_way_to_manipulate_asts/).

Expand Down
9 changes: 4 additions & 5 deletions docs/syntax/switch.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
The Switch Statements
===============================

In the real use of pattern matching provided by MLStyle,
things can sometimes becomes painful. To end this, we have `@when`, and now even **`@switch`**.
Not all real-world code is most conveniently expressed using `@match`. To help with some common pain-points, we have included `@when`, and **`@switch`**.

Following code is quite stupid in many aspects:
The following example demonstrates a common pattern that is unnecessarily verbose:

```julia
var = 1
Expand All @@ -17,7 +16,7 @@ var = 1

Firstly, capturing in `@match` just shadows outer variables, but sometimes you just want to change them.

Secondly, `@match` is an expression, and the right side of `=>` can be only an expression, and writing a `begin end` there can bring bad code format.
Secondly, `@match` is an expression, and the right side of `=>` can only be an expression. Therefore writing `begin` or `end` statements can bring about an undesirable code format.

To address these issues, we present the `@switch` macro:

Expand All @@ -42,4 +41,4 @@ julia> @switch 1 begin
println(var)
end
ERROR: matching non-exhaustive, at #= REPL[25]:1 =#
```
```
17 changes: 8 additions & 9 deletions docs/syntax/when.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
When Destructuring
===========================

The `@when` is introduced to work with the scenarios where `@match` is a bit heavy.
The `@when` macro was introduced to work with the scenarios where `@match` leads to heavy syntax.

It's similar to [if-let](https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html) construct in Rust language.


There're three distinct syntaxes for `@when`.
There are three distinct syntaxes for `@when`.

Allow Destructuring in Let-Binding
-----------------------------------------------------------------
Expand Down Expand Up @@ -45,7 +45,7 @@ s = S1(5)
end
```

In above snippet, `@inline fn(x) = 100x` is not regarded as destructuring.
In the above snippet, `@inline fn(x) = 100x` is not regarded as destructuring.


Sole Destructuring
Expand Down Expand Up @@ -74,10 +74,9 @@ Sometimes we might have this kind of logic:
- otherwise do `Cc`


As there is now no pattern matching support for `if-else`,
we cannot represent above logic literally in vallina Julia.
As there is currently no pattern matching support for `if-else`, we cannot represent above logic literally in vallina Julia.

MLStyle provides this, in such a syntax:
MLStyle provides this, with the following syntax:

```julia
@when let A = a
Expand All @@ -89,7 +88,7 @@ MLStyle provides this, in such a syntax:
end
```

Also, predicates can be used here, thus it's superior than
Also, predicates can be used here, thus it can be seen as superior to
`if-else`:

```julia
Expand All @@ -105,7 +104,7 @@ Also, predicates can be used here, thus it's superior than
end
```

A concrete example is presented here:
A concrete example is presented below:

```julia
a = 1
Expand All @@ -115,4 +114,4 @@ b = 2
@when begin a::Int = b; (b < 10).? end
0
end # => 0
```
```
14 changes: 7 additions & 7 deletions docs/tutorials/capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ Static Capturing
We know that `MacroTools.jl` has brought about a useful macro
`@capture` to capture specific structures from a given AST.

As the motivation of some contributors, `@capture` of `MacroTools.jl` has 3 following shortages.
As the motivation of some contributors, `@capture` of `MacroTools.jl` has the following 3 short comings.

- Use underscore to denote the structures to be captured, like `struct typename_ field__ end`, which makes you have to manually number the captured variables and not that readable or consistent.
- An underscore is used to denote the structures which are to be captured, like `struct typename_ field__ end`, which makes you have to manually number the captured variables. This is not very readable or consistent.

- Cause Side-Effect. The captured variables are entered in current scope.
- Causes Side-Effects. The captured variables are entered in current scope.

- Lack functionalities like conditional capturing.
- Lacks functionalities like conditional capturing.

We can implement several new `@capture` via MLStyle.jl to get better in all aspects.
We can implement several new `@capture` via MLStyle.jl to get better results in all of these aspects.

`Capture` Pattern from `MLStyle.Modules.AST`:
----------------------------------------------------------

MLStyle now can collaborate with scope information very well. You can get the captured(by pattern matching) variables in one point of your program.
MLStyle now can collaborate with scope information very well. You can get the captured variables by pattern matching in one point of your program.

```julia
using MLStyle.Modules.AST
Expand Down Expand Up @@ -67,4 +67,4 @@ node2 = :(f(x))
end

# do nothing
```
```
Loading