Skip to content

Instantly share code, notes, and snippets.

baroquebobcat / sake_scheduler.rb
Last active Aug 29, 2015
A tool for planning sake making
View sake_scheduler.rb
# Sake Brewing Scheduler
require 'date'
def dfmt date
case date
when Date
date.strftime "%a, %b %e"
when Range
[date.first,date.last].map{|d|dfmt(d)}.join(" - ")
baroquebobcat /
Last active Aug 29, 2015
Mirah Extensions

Extension Methods

In the Mirah compiler, you can make Macros that work on std lib / predefined classes. You can't, however, do it in your own code easily at the moment. You can add macros that apply to your own types but not others. Here's some ideas for an API to change that.



baroquebobcat /
Created Jun 16, 2014
Mirah Macro Help: Some macro notes

If you want to unquote the args from a block, be sure to not include the pipes.


quote do
  `list`.each { `block.arguments` cool_thing; `[block.body]` }



Mirah Scoping and control structures

If statements

If statements don't introduce a new scope, like ruby, but they are a little tricky.

For example, if b is false in the following, what would a be?


JVMLS Notes Day 1

Mirah NLR + yield

Thought I came up w/ talking w/ headius + kotlin dev

Have nonlocal return allowed only for blocks passed to fns that are either: macros, or take a specialized type that's generated from a yield


Dreams of Mirah 1.0

What is Mirah?

Runtimeless JVM language that tries as hard as possible to feel like writing Ruby without cheating.

  • Should produce class files that are drop in replacements for Java.
  • Should interop well with Java and Java tools
  • It'd be nice if it interopped well with JRuby too, as well as other JVM langs, through compiler extensions.
  • It should have an extensible compiler

constants work by being translated into field accesses / assigns.

to ensure that constants that are seen before they are assigned can be resolved, the mirror typer keeps a hash of fields that it has seen, but haven't been assigned or declared yet.

View extensionmethods.mirah
package cool.extensions
extension StringExt[String]
def toInt
# or, less overloaded w/ generics
View dynamical.rb
class Dynamical
define_method :works_fine do |&block|
5.times { |n| }
def self.defn name
define_method name do |&block|
5.times { |n| yield n }


Extensions are the way that Mirah adds methods to existing classes. When you call methods like each on collections, you are actually using extensions. They are helpful when you want to write DSLs and when you want to make a library you are using feel more Mirah-ish.

How do you use them?

Mirah comes with a number of built in extensions for Java's base types. For example, the methods each, map and empty are added to Collections. The built in extensions need no special invocation to be taken advantage of, they're already available. If you want to use extensions from a library, or optional extensions, you'll need to tell Mirah which ones you want to use.

The way you do that is by "using" the extension. using works just like import, but instead of making an imported class available, they extend other classes. For example, say you wanted to pluralize a string using an activesupport-like library. You could do it like so: