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