public
Last active

Some random notes on Mirah, mostly culled from the mailing list

  • Download Gist
gistfile1.mkd
Markdown

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

h2. =begin / =end

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

h2. 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.

http://groups.google.com/group/mirah/msg/5a8923432da594ed

h2. Extending an existing Java class

is not currently supported, but is on the roadmap:

http://groups.google.com/group/mirah/msg/b3d5b34f9be0ecf8

h2. 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

h2. HEREDOC is supported

http://groups.google.com/group/mirah/browse_thread/thread/b9cec92232187890

h2. 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)) {...} "

http://groups.google.com/group/mirah/msg/d6b0a971d61c17ae

h1. Stuff in Java that is/isn't supported

h2. interfaces

are there.

http://groups.google.com/group/mirah/browse_thread/thread/6832ae248bf41bca#

h2. long integers

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

http://groups.google.com/group/mirah/msg/3d03b1be06277b5e

h2. parameterized types (generics, type parameters)

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

http://groups.google.com/group/mirah/msg/59b7a047fc854b93

h2. 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"

http://groups.google.com/group/mirah/browse_thread/thread/3a35eeed574e5310#

h2. Annotations

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

http://groups.google.com/group/mirah/browse_thread/thread/37705643114f5d4a#

h2. Exceptions

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

h2. 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."

h2. packages

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"

http://groups.google.com/group/mirah/browse_thread/thread/7d76cdf6b99f9ab2#

h1. Stuff that's unique to mirah

h2. Macros

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

http://groups.google.com/group/mirah/browse_thread/thread/c6c4df3f6a40d05e# http://groups.google.com/group/mirah/browse_thread/thread/4960d2b5d2d98861#

h1. Android

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

http://groups.google.com/group/mirah/browse_thread/thread/8c0f5f320e85e357

h1. Bugs and troubleshooting

h2. InferenceError

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

h2. 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

h2. java.lang.VerifyError

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

http://groups.google.com/group/mirah/msg/79db781723b8c7b1

Mirah now seems to support optional args:

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

I think it extends java classes now, too.

yield isn't yet supported
also here's how to do def [] http://groups.google.com/group/mirah/browse_thread/thread/2812bb4a119b9b1 currently

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.