Macro type help

That went way over my head as I don’t I don’t understand the compiler internals .

To me the ideal language would have macros as the language, only evaluated at compile time. Is this the sorcery you speak of?

That’s how macros currently work, except that they are interpreted.

I meant this:

p File.read("test")[0, 5]
p {{ File.read("test")[0, 5] }}

Error

undefined macro method 'TypeNode#read'

p {{ File.read("test")[0, 5] }}

Correct, in macro land a type is represented as a https://crystal-lang.org/api/master/Crystal/Macros/TypeNode.html. Which has its own unique set of methods since your interacting with the actual AST node, not the actual File class.

My example is what I would consider ideal. Everything you can do in the language you could wrap in a macro without changes. Maybe there are additional methods or classes only available for macros like AST (until there’s a JIT). Am I the only one that wants that?

1 Like

We all want that, maybe. But it’s hard to implement. However, Elixir does that, so you can try that language.