Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
baroquebobcat / sake_scheduler.rb
Last active August 29, 2015 13:56
A tool for planning sake making
# 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(" - ")
end
@baroquebobcat
baroquebobcat / ext.md
Last active August 29, 2015 13:58
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.

Related

Questions

@baroquebobcat
baroquebobcat / mirah_macro_help.md
Created June 16, 2014 04:12
Mirah Macro Help: Some macro notes

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

#Correct

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

#Wrong

@baroquebobcat
baroquebobcat / mirah_scope.md
Last active August 29, 2015 14:04
Mirah Scoping

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

@baroquebobcat
baroquebobcat / dreams_of_mirah_1.0.md
Last active August 29, 2015 14:05
Dreams of Mirah 1.0

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.

package cool.extensions
extension StringExt[String]
def toInt
Integer.parseInt(self)
end
end
# or, less overloaded w/ generics
class Dynamical
define_method :works_fine do |&block|
5.times { |n| block.call(n) }
end
def self.defn name
define_method name do |&block|
5.times { |n| yield n }
end
end
@baroquebobcat
baroquebobcat / mirah_extension_proposal.md
Created February 8, 2015 03:09
Mirah Extension Proposal

Extensions

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: