Skip to content

Instantly share code, notes, and snippets.

Created November 17, 2010 22:46
What would you like to do?
Some random notes on Mirah, mostly culled from the mailing list

Stuff in Ruby that is/isn't supported, or is different

=begin / =end

Rib Rdb writes: "The new parser doesn't support this". Use single line comments instead

The object model

The ruby object model is not the same as the java object model. The difference people seem to come up against most often is in static methods. Rib Rdb again: " Static and instance methods are all lumped together, so you can't have an instance method with the exact same name/arguments as a static method. I believe the same thing goes for fields"

You may also run into inheritance issues: see e.g.

Extending an existing Java class

is not currently supported, but is on the roadmap:

optional args : not supported, use method polymorphism instead

mirah doesn't do optional method args in the ruby way. However, you can (like java) have have multiple methods with the same name and different arguments

HEREDOC is supported

the ruby standard library

The Ruby standard library is by and large not part of Mirah: try using the equivalent Java functionality instead where available. For example,

"You can use Collections.sort(list) {|a, b| ... }

There's also Arrays.sort, but I don't think we support converting arrays to Object[], so you'd have to use Collections.sort(Arrays.asList(array)) {...} "

Stuff in Java that is/isn't supported


are there.

long integers

The L suffix for literal numbers is not supported but will be

parameterized types (generics, type parameters)

are not suported "but that really shouldn't matter; since the JVM erases generic types at runtime" - Charles Nutter

static fields

"Someone asked me today if Mirah supported static fields, and I had forgotten the answer. So I poked around and remembered that instance vars in static methods end up being static"


"Yes. We use $ instead of @. For example $Deprecated def foobar; end The source code compiler doesn't support annotation values, but the bytecode backend should support string, class, and annotation values, as well as arrays of those types. We use square brackets instead of parens around the values: "


"We use ruby's syntax for exceptions (except we don't support retry or catch/throw). "

"If you want to declare which exceptions a method throws you use the throws macro [...] This is only required if you're using the .java backend though as the .class backend doesn't check exceptions."

[ editorial interjection: praise be unto (Allah|the Lord|the FSM|Linus)! Exception checking was always one of java's uglier misfeatures ]

final and void

"in java final means the variable can't be modified after it's initialized, and you need to use it for all variables you access in a java closure. Mirah has mutable closures so we don't have that restriction, and there's no way to mark something final. "

"If you're subclassing a java class or implementing an interface with a void method we should be able to infer that automatically. The only time you need to specify void is if you want force a method to return void."


I have tried 'package' keyword at top of the mirah script but that does not work. Is it possible to compile mirah script into a package at this stage of development?

"Right now the package comes from the directory of the file. So if you run mirahc foo/bar.mirah you get the class foo.Bar"

Stuff that's unique to mirah


The example didn't work when I cut and pasted (may be obsolete,or I may be misunderstanding the contexts in which macros can be used). But you dear reader are probably smarter than me, so try it yourself


Garrett (on github) is an example Android app written in Mirah.

Mirahndroid (working name, may soon be called Pindah) is a script originally derived from Garrett which generates a skeleton android project in mirah

Bugs and troubleshooting


InferenceError usually means "something went wrong and we don't have a more specific error message". Could be pretty much anything

backends out of sync

The jvm backand and the java source backend are sometimes out of sync: certain stuff might work in one but not the other


Rib Rdb writes "Any time you get a java.lang.VerifyError you've found a bug in mirah. Unfortunately as you found the JVM isn't very helpful in explaining what that bug is. If you set the environment variable BS_CHECK_CLASSES=true and recompile the file you should hopefully get a better description of the problem."

Copy link

rdp commented May 26, 2011

Mirah now seems to support optional args:

  def foo(a:int, b:int = 1, c:int = 2)
        puts a; puts b; puts c

Copy link

rdp commented May 30, 2011

I think it extends java classes now, too.

Copy link

rdp commented Jul 18, 2011

yield isn't yet supported
also here's how to do def [] currently

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