JuliaAI / MLJBase.jl

Core functionality for the MLJ machine learning framework
MIT License
160 stars 45 forks source link

@mlj_model macro fails on negative default args [needs docs for way around] #68

Closed tlienart closed 2 years ago

tlienart commented 4 years ago
julia> @mlj_model mutable struct Blah
       a::Int = -1::(_ > -2)
       end
ERROR: syntax: extra token "::" after end of expression

I'm investigating, the issue is that -5 is effectively an op

tlienart commented 4 years ago

right so that won't be easy to directly fix; there's something to do with when that - is evaluated. Interestingly this works fine:

neg(a) = -a
@mlj_model mutable struct Foo
  a::Int = neg(1)::(_ > -2)
end

So I guess we can either try the hard way which is to fix this (it's not clear to me how); or document that users should use such a neg for negative default vals (which will likely be rare).

tlienart commented 4 years ago

A bit less hacky (would still need to be documented)

@mlj_model mutable struct Bar
    a::Int = (-)(1)::(_ > -2)
end
ablaom commented 4 years ago

@tlienart Thanks for that. Good catch.

While this is annoying, I think it low priority. I vote for the documented hack.

ablaom commented 4 years ago

Closing in favour of above MLJ 504

ablaom commented 4 years ago

MLJ 504 is just a documentation issue.

ablaom commented 2 years ago

Since this issue was opened we've not actually bumped against it. I think the documentation warning, already added suffices and am closing.