Skip to content

Commit e43325c

Browse files
aviateskMikeInnes
authored andcommitted
updatedocs (#125)
* fix broken example * only show static parameter examples with where syntax * avoid verbose code example * simplify rebuild function definition example
1 parent 0e00756 commit e43325c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

docs/src/pattern-matching.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Because `@capture` doubles as a test as well as extracting values, you can
4848
easily handle unexpected input (try writing this by hand):
4949
5050
```julia
51-
@capture(ex, f_{T_}(xs__) = body_) ||
51+
@capture(ex, f_(xs__) where {T_} = body_) ||
5252
error("expected a function with a single type parameter")
5353
```
5454
@@ -97,18 +97,18 @@ which will match e.g. `struct Foo ...` but not `struct Foo{V} ...`
9797
for example:
9898
9999
```julia
100-
@capture(ex, f_(args__) = body_ | function f_(args__) body_ end)
100+
@capture(ex, (f_(args__) = body_) | (function f_(args__) body_ end))
101101
```
102102
103103
will match both kinds of function syntax (though it's easier to use
104104
`shortdef` to normalise definitions). You can also do this within
105105
expressions, e.g.
106106
107107
```julia
108-
@capture(ex, (f_{T_}|f_)(args__) = body_)
108+
@capture(ex, (f_(args__) where {T_}) | (f_(args__)) = body_)
109109
```
110110
111-
matches a function definition, with a single type parameter bound to `T` if possible.
111+
matches a function definition like `func(a::T) where {T<:Number} = supertype(T)`, with a single type parameter bound to `T` if possible.
112112
If not, `T = nothing`.
113113
114114
## Expression Walking

docs/src/utilities.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ the full range of function syntax.
3535
`splitdef(def)` matches a function definition of the form
3636

3737
```julia
38-
function name{params}(args; kwargs)::rtype where {whereparams}
38+
function name(args; kwargs)::rtype where {whereparams}
3939
body
4040
end
4141
```
@@ -45,11 +45,10 @@ calling `MacroTools.combinedef(dict)`, or explicitly with
4545

4646
```julia
4747
rtype = get(dict, :rtype, :Any)
48-
all_params = [get(dict, :params, [])..., get(dict, :whereparams, [])...]
49-
:(function $(dict[:name]){$(all_params...)}($(dict[:args]...);
50-
$(dict[:kwargs]...))::$rtype
51-
$(dict[:body])
52-
end)
48+
:(function $(dict[:name])($(dict[:args]...);
49+
$(dict[:kwargs]...))::$rtype where {$(dict[:whereparams]...)}
50+
$(dict[:body].args...)
51+
end)
5352
```
5453

5554
`splitarg(arg)` matches function arguments (whether from a definition or a function call)

0 commit comments

Comments
 (0)