Skip to content

Instantly share code, notes, and snippets.

@chrisseaton
Created July 11, 2015 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisseaton/4464807d93b972813e49 to your computer and use it in GitHub Desktop.
Save chrisseaton/4464807d93b972813e49 to your computer and use it in GitHub Desktop.
$ jt run --graal test/truffle/can-we-fold-yet.rb test/truffle/can-we-fold-yet.rb
Can Truffle constant fold yet?
> 14
Yes! Truffle can constant fold this to 14
> 14 + 2
Yes! Truffle can constant fold this to 16
> eval([1, 2, 3].inspect).sort[1] * 2
Yes! Truffle can constant fold this to 4
> eval(rand < 0.5 ? '14 - 2' : '10 + 2')
Yes! Truffle can constant fold this to 12
> eval('rand')
No :( Truffle can't constant fold that
@chrisseaton
Copy link
Author

It's because strings are mutable. A dynamic value 14 is the same as a constant value 14, but 'foo' + 'bar' generates a new value each time, so it's not clear how to make that constant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment