Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baroquebobcat/10328625 to your computer and use it in GitHub Desktop.
Save baroquebobcat/10328625 to your computer and use it in GitHub Desktop.
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

  • Scoping: Over what set of files should the extensions be visible? Everything in a compile that includes them?
  • Definition API: Separate files? Open classes? Separate DSL? Invoking things on the compiler?

###Scoping

I think we should start w/ having global extensions.

API

"open" classes

They could look like open classes

class java.util.ArrayList
  macro def reduce(block: Block)
    #  ...
  end
end

It'd be a little tricky because w/ that it looks like you can add methods as well, but you can't.

extension keyword ala interface

extension java.util.ArrayList
  macro def reduce(block: Block)
    #  ...
  end
end

The thing I don't like about this is that it doesn't have a name. Names are nice for source locations when things have problems.

Maybe

extension MyCoolExtensions of java.util.ArrayList
  # ...
end

Or, we could split that up

extension MyCoolExtension
  macro def blah
    # ...
  end
end

register_extension MyCoolExtension on: java.util.ArrayList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment