type of evaluation in Ruby

Hello. Ruby what kind of evaluation do you have ?, according to I have
a strict evaluation, since in the following code in the variable the
addition and subtraction are evaluated.

#ruby 2.3.1

a = 3 + 2
b = 10-5
c = (a + b) / (a-b)

puts "hello world!"

Unsubscribe: <>


Re: type of evaluation in Ruby

By Robert Klemme at 04/12/2018 - 02:08

On Wed, Apr 11, 2018 at 6:33 PM, Hugo Alberto Gómez Gutiérrez
< ... at ciencias dot> wrote:
According to what?

A variable holds a reference to an object (leaving details of tagged
pointers aside). There is no "code in the variable" nor is there
anything evaluated "in" the variable.

As far as I am aware Ruby uses strict evaluation unless the runtime
system does otherwise. If you run JRuby then there is a chance that
the JVM does some reordering on the byte code level and might skip
operations. But I do not think this has effects on what you see on the
Ruby language level.

Btw. by definition you could not observe what evaluation strategy Ruby
uses just by running a Ruby program. The whole point of lazy
evaluation is that it optimizes execution but does not change the
semantics. :-)