Live data from Hacker News

Opal - Ruby to Javascript compiler

opalrb.org

51–54 of 54 posts

Re: Opal - Ruby to Javascript compiler

#51
post #48
post #40

Earlier quoted context omitted.

Gah, the website ruined what I was typing. I meant 2 to the power of 100. Which is a 100 bit integer, and certainly not correctly calculated in JavaScript.

While your general point is correct, the details aren't. Powers of 2 are represented exactly in floating point (for any number, only the 53 most significant bits can be stored). So 2^100 + 1 is an example of something that's non-representable in JS.

We could have a philosophical debate about what number a finite precision representation represents when you exceed its precision. But on a practical level, if you print it, what do you get? An exact integer, or a floating point representation?

Re: Opal - Ruby to Javascript compiler

#52
post #51
post #48

Earlier quoted context omitted.

While your general point is correct, the details aren't. Powers of 2 are represented exactly in floating point (for any number, only the 53 most significant bits can be stored). So 2^100 + 1 is an example of something that's non-representable in JS.

We could have a philosophical debate about what number a finite precision representation represents when you exceed its precision. But on a practical level, if you print it, what do you get? An exact integer, or a floating point representation?

[deleted]

Re: Opal - Ruby to Javascript compiler

#53

It's a great idea, but it seems ridiculous how even simple arithmetic gets translated to an unreadable mess of javascript. puts 4 + 2 + 5 + (19 + 3 * 4) - 8 / 10 translates to: (function() { var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice; var __a, __b, __c, __d, __e, __f, __g, __h; return self.$puts((__a = (__c = (__e = (__g = 4, __h = 2, t…

the problem is that ruby lets you redefine + anywhere you like, and return values of any type. so you need the most general translation of that expression into a series of method dispatches.

Re: Opal - Ruby to Javascript compiler

#54

Cool idea. Not the first attempt though: http://hotruby.yukoba.jp/ https://github.com/whitequark/coldruby http://rb2js.rubyforge.org/ http://www.ntecs.de/blog/articles/2007/01/08/rubyjs-javascri... https://github.com/jessesielaff/red http://www.playmycode.com/docs/quby https://github.com/mattknox/8ball Unfortunately, none of them seem to be to handle the mor dynamic features of ruby, like method_missing , which dimin…

Opal does support method_missing, it's just off by default, i.e. opt-in.
Post reply on HN