type of evaluation in Ruby


(Hugo Alberto Gómez Gutiérrez) #1

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!"


(Robert K.) #2

Hello. Ruby what kind of evaluation do you have ?, according to I have

According to what?

a strict evaluation, since in the following code in the variable the
addition and subtraction are evaluated.

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.

#ruby 2.3.1

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

puts "hello world!"

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. :slight_smile:

Cheers

robert

···

On Wed, Apr 11, 2018 at 6:33 PM, Hugo Alberto Gómez Gutiérrez <hugo_gomez@ciencias.unam.mx> wrote:

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/