News for hackers. Stuff that matters.
Re:Why Does Julia Work So Well? by rcthompson on Wednesday October 21, 2020 @08:03AM (#24846942)
Does anyone know why the text claims that "2^-5" is an error, but the output shows it returning 0.03125?
Re:Why Does Julia Work So Well? by kristofferc on Wednesday October 21, 2020 @08:05AM (#24846952)
It used to error, but exponentiation with negative literal integers was made to work. Perhaps the notebook hasn't been updated since then.
Re:Why Does Julia Work So Well? by rcthompson on Wednesday October 21, 2020 @08:36AM (#24847145)
I would be interested to read how they made it work, given that it seems to violate the principle of type-stability. Did they just implement the slow runtime type check, or did they do something clever?
Re:Why Does Julia Work So Well? by dklend122 on Wednesday October 21, 2020 @08:39AM (#24847183)
I think it's parsed specially, but I could be wrong.

Definitely no runtime check

Re:Why Does Julia Work So Well? by improbable22 on Wednesday October 21, 2020 @08:52AM (#24847313)
It goes to `literal_pow`, one way to check is to overload this:

    Base.literal_pow(::typeof(^), x::Int, ::Val{n}) where {n} = 
        (println("power $n"); float(x)^n)
    pow = -5
    2^-5    # yes
    2^pow   # no, hence an error
Re:Why Does Julia Work So Well? by ChrisRackauckas on Wednesday October 21, 2020 @11:13AM (#24848611)
Yes indeed: these are workshop notes from 2017 so it's a little old. In fact, it's surprising to see on Hacker News haha.