thx.core icon indicating copy to clipboard operation
thx.core copied to clipboard

Int gets coerced to Time somehow?

Open TiZ-HugLife opened this issue 10 years ago • 3 comments

I'm still trucking along in learning Haxe by doing /r/dailyprogrammer challenges. One of the minis for the week has me calculate the number of "ramp numbers" less than a given number. This program should solve it:

using Thx;
class RampNums {
    static function main () {
        var rampNums = 0, arg = Sys.args()[0].ifEmpty("100");
        for (i in 1 ... (arg.canParse() ? arg.toInt() : 100)) 
            if (i.toString() == i.toString().toArray().order.fn(
             _0.toInt() - _1.toInt()).join("")) rampNums++;
        Sys.println(rampNums.toString());
    }
}

However, when I run the generated bin through the cpp build, I get a time: 1969-12-31 19:00:00 And when I build with neko and run that, I get a crash...

Called from ? line 1
Called from RampNums.hx line 6
Called from RampNums.hx line 6
Called from thx/Iterators.hx line 147
Called from /usr/lib/haxe/std/neko/_std/Array.hx line 344
Called from a C function
Called from RampNums.hx line 7
Uncaught exception - Invalid operation (-)

Do you have any ideas in regards to this weirdness?

TiZ-HugLife avatar Oct 12 '15 02:10 TiZ-HugLife

Can you try to reduce that code to a minimal sample? It is really hard to pin point what is going wrong there.

fponticelli avatar Nov 03 '15 23:11 fponticelli

Seems like this is enough to reproduce it: http://try.thx-lib.org/#Cd0F4

If you remove the .toString() in the trace(), it outputs the correct number.

mlms13 avatar Nov 03 '15 23:11 mlms13

Thanks, it is a precedence issue. Will fix it.

fponticelli avatar Nov 03 '15 23:11 fponticelli