Problem with recursive fibonacci example

39 views
Skip to first unread message

Michael Fairley

unread,
Jan 2, 2012, 3:29:45 AM1/2/12
to The Mirah Programming Language
Am I doing something wrong, or is this a regression?

$ mirah -v
Mirah v0.0.10

$ cat fib.mirah
def fib(a:fixnum):fixnum
if a < 2
a
else
fib(a-1) + fib(a-2)
end
end
puts fib(3)

$ mirah fib.mirah
fib.mirah:25: Cannot find instance method +(fib) on fib
fib(a-1) + fib(a-2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mirah::InternalCompilerError: Cannot find instance method +(fib) on
fib
infer at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:280
resolve at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:324
each at org/jruby/RubyHash.java:1170
resolve at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:322
cycle at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:236
times at org/jruby/RubyFixnum.java:256
cycle at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:233
resolve at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/typer/simple.rb:319
infer_asts at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/generator.rb:49
generate at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/generator.rb:35
execute at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/commands/run.rb:30
execute_base at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/commands/base.rb:41
catch at org/jruby/RubyKernel.java:1192
execute_base at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/commands/base.rb:38
execute at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah/commands/run.rb:23
run at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/lib/mirah.rb:36
(root) at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/gems/
mirah-0.0.10-java/bin/mirah:27
load at org/jruby/RubyKernel.java:1063
(root) at /Users/michaelfairley/.rvm/gems/jruby-1.6.5/bin/
mirah:19

Keith Swallow

unread,
Jan 2, 2012, 1:24:28 PM1/2/12
to mi...@googlegroups.com
Hi Michael,

I installed Mirah on JRuby 1.6.5 and do not see the same behavior. Perhaps something compiled wrong? How did you install Mirah?

$ mirah -v
Mirah v0.0.10

...

$ cat fib.mirah
def fib(a:fixnum):fixnum
if a < 2
a
else
fib(a-1) + fib(a-2)
end
end
puts fib(3)

$ mirah fib.mirah
2

Best,

Keith

Nick Howard

unread,
Jan 2, 2012, 1:38:59 PM1/2/12
to mi...@googlegroups.com
I couldn't reproduce it either. I also noticed that the error is supposedly on line 25 of fib.mirah, which may also be a bug.

 fib.mirah:25: Cannot find instance method +(fib) on fib
        fib(a-1) + fib(a-2)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Could you try running the recursive fib example (https://github.com/mirah/mirah/blob/master/examples/fib.mirah) and see if that works?

Michael Fairley

unread,
Jan 2, 2012, 2:59:19 PM1/2/12
to mi...@googlegroups.com
The line 25 thing was my fault – I had a bunch of stuff commented out at the top of the file. Taking it all out gives the expected line number (5).

Looks like the problem was that I had a Fib.class and Fib.java living along side it, which mirah automatically picked up.
Reply all
Reply to author
Forward
0 new messages