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

Switch to more local @_ #26

Closed
MasonProtter opened this issue Feb 20, 2023 · 5 comments
Closed

Switch to more local @_ #26

MasonProtter opened this issue Feb 20, 2023 · 5 comments

Comments

@MasonProtter
Copy link

So I realized here: JuliaLang/julia#38713 (comment) that we actually can have map(@_ 1 + _[1], v) or whatever do the right thing. Maybe this should be the canonical usage of this macro instead of being outside the map.

@MasonProtter MasonProtter changed the title Switch to more local @_. Switch to more local @_ Feb 20, 2023
@mcabbott
Copy link
Collaborator

Oh that's pretty magical, I didn't know we could return "naked" tuples. Splat at production not consumption. Mathematica has something like this, but I thought Julia didn't.

julia> map(@_ _^2, [1 2 3])
1×3 Matrix{Int64}:
 1  4  9

julia> @macroexpand1(@_ _^2, [1 2 3])
:(((var"##x#301"->begin
              #= REPL[12]:12 =#
              var"##x#301" ^ 2
          end), [1 2 3])...)

julia> dump(ans)
Expr
  head: Symbol ...
  args: Array{Any}((1,))
    1: Expr
      head: Symbol tuple

@MasonProtter
Copy link
Author

I feel quite silly because I've known we could do this for years, but never made the connection that it could be used to bypass JuliaLang/julia#36547

@tpapp
Copy link

tpapp commented Feb 21, 2023

Oh that's pretty magical, I didn't know we could return "naked" tuples.

Is this documented anywhere?

@MasonProtter
Copy link
Author

Since this would be a major departure from how this package works, I think I'll close this in favour of just making a new package: https://github.com/MasonProtter/SimpleUnderscores.jl

@c42f
Copy link
Owner

c42f commented Feb 22, 2023

Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants