These are chat archives for opal/opal

27th
Mar 2016
Bernhard Weichel
@bwl21
Mar 27 2016 17:33

It appears that opal dos not make a real difference between lambda and proc:

def runwithlambda()
  puts "runwithlambda"
  ap1 = lambda{ |i| return " explicit return >2" if i > 2
    "implicit return #{i} " + ap1[i+1]
  }

  return ap1[0]
end


def runwithproc()
  puts "runwithproc"
  ap1 = proc{ |i|
    return " explicit return >2" if i > 2
    "implicit return #{i} " + ap1[i+1]
  }

  return ap1[0]
end

puts runwithproc()

puts runwithlambda()

Run with opal:

> opal vl.rb
runwithproc
 explicit return >2
runwithlambda
 explicit return >2

We see that in both cases return also returns from the containing method in both cases.

Runs with ruby 2.2.1:

ruby vl.rb
runwithproc
 explicit return >2
runwithlambda
implicit return 0 implicit return 1 implicit return 2  explicit return >2

We see that only runwithproc return also returns from the containing method in both cases.

Is it a bug in Opal or an unsupported feature.

Bernhard Weichel
@bwl21
Mar 27 2016 17:39
I see that opal/opal#260 is still open, so I stumbled in this issue again. Is there any chance to get a fix on that?
Lars Haugseth
@lhz
Mar 27 2016 19:39
Just tried to update from 0.8 to 0.9.2 in an app here since I wanted Array#each_cons, which wasn't implemented before. Now I have a hard time getting methods with kwargs to work. I get this error: Uncaught TypeError: Cannot read property 'x' of undefined
Generated code that breaks:
    Opal.defn(self, '$rect', function($kwargs) {
      var $a, $b, TMP_5, $c, TMP_6, self = this, x = nil, y = nil, w = nil, h = nil, color = nil, fill = nil;

      if ($kwargs == null) {
        $kwargs = $hash2([], {});
      }
      if (!$kwargs.$$is_hash) {
        throw Opal.ArgumentError.$new('expecting keyword args');
      }
      if ((x = $kwargs.$$smap['x']) == null) {
Last of those lines results in the type error.
Method definition is: def rect(x: , y: , w: , h: , color: nil, fill: nil)
Calling it like this: rect x: 0, y: 0, w: 384, h: 288, fill: 15
Elia Schito
@elia
Mar 27 2016 20:20
@bwl21 differentiating between prix and lambda is a bit tricky, but don't remember if anything has been done already on master
@lhz can you check if it's still broken on master?
Lars Haugseth
@lhz
Mar 27 2016 20:21
@elia will give it a shot
Bernhard Weichel
@bwl21
Mar 27 2016 20:22
@elia I think it should at least be mentioned in the list of unsupported features
Lars Haugseth
@lhz
Mar 27 2016 20:26
@elia will try with ruby 2.2.4 first, using 2.3.0 at the moment.
Bernhard Weichel
@bwl21
Mar 27 2016 21:06

@elia, could you have a quick look at Phrogz/NeatJSON#9

There is the proposal: "You might petition the Opal team to consider an option to "transpile" Ruby hashes to Javascript Map objects, which preserve ordering."

Elia Schito
@elia
Mar 27 2016 22:26
@bwl21 it's a bug, in the sense that it's meant to be supported in the future, we keep a list of stuff that should be implemented in spec/filters/bugs/ in the Opal repo
Elia Schito
@elia
Mar 27 2016 23:04
@lhz which CRuby version you use to compile to js shouldn't matter