Comment

Comment by eesmith

Ahh, so Ruby doesn't - and can't[1] - support constant folding.

In CPython, because monkey-patching like this isn't supported, the byte compiler turns a "0/2" into a "0.0", as you can see with:

  >>> def f():
  ...   return 0 / 2
  ...
  >>> import dis
  >>> dis.dis(f)
    2           0 LOAD_CONST               1 (0.0)
                2 RETURN_VALUE
[1] EDIT: except through something like whole-program analysis.
parent eesmith 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton