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

Recurse _ past macros too #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/Underscores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function lower_inner(ex)
elseif ex.head in _square_bracket_ops
# Indexing & other square brackets not counted as outermost function
return Expr(ex.head, map(lower_inner, ex.args)...)
elseif ex.head == :macrocall
# Indexing & other square brackets not counted as outermost function
return Expr(ex.head, map(lower_inner, ex.args)...)
elseif ex.head == :. && length(ex.args) == 2 && ex.args[2] isa QuoteNode
# Getproperty also doesn't count
return Expr(ex.head, map(lower_inner, ex.args)...)
Expand Down Expand Up @@ -207,6 +210,8 @@ This excludes the following operations:
and hence to pass the anonymous function to `sum` instead. This also applies to
broadcasted operators, such as `map(_^2,x) ./ length(x)`.

* Macros also aren't treated as function calls.

The scope of `__` is unaffected by these concerns.

| Expression | Meaning |
Expand All @@ -217,6 +222,8 @@ The scope of `__` is unaffected by these concerns.
| `@_ sum(_^2,a) / length(a)` | `sum(x->x^2,a) / length(a)` |
| `@_ /(sum(_^2,a), length(a))` | The same, infix form is canonical. |
| `@_ data \\|> filter(_>3,__).^2` | `data \\|> d->(filter(>(3),d).^2)` |
| `@_ @view A[findall(_<2, A)]` | `@view A[findall(x->x<2, A)]` |
| `@_ @view(A[findall(_<2, A)])` | The same, brackets are optional. |

"""
macro _(ex)
Expand Down