Julia: Underscore not allowed with optional parameters

Created on 29 Jul 2019  Â·  4Comments  Â·  Source: JuliaLang/julia

julia> f(_, a) = 10
f (generic function with 1 method)

julia> f(_, a=1) = 10
ERROR: syntax: all-underscore identifier used as rvalue around REPL[0]:1

The second form seems legitimate, no? The same issue arises with keyword arguments (f(_; x=1) = ...)

feature help wanted lowering

Most helpful comment

Could be nice to lower _ as a function argument to @nospecialize(_)

All 4 comments

It does seem like a good way to indicate that you don't care about an argument, similar to ::Any but shorter.

Ah, naturally this is due to lowering converting the definition to

f(_) = f(_, 1)
f(_, a) = 10

Could be nice to lower _ as a function argument to @nospecialize(_)

how does the lowering for keyword arguments look like? is it the same reason there?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

m-j-w picture m-j-w  Â·  3Comments

wilburtownsend picture wilburtownsend  Â·  3Comments

felixrehren picture felixrehren  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments