I have a question about what's possible (or what w...
# arrow-meta
n
I have a question about what's possible (or what will be possible in the future) with compiler plugins: Java annotations have limitations as to what arguments they can take. For instance, annotations can't take functions as arguments. Would it be possible to have code like the following compile with a compiler plugin?
Copy code
@Rule {
    if (parentOf(X,Y) && parentOf(Y,Z)
        grandparentOf(X,Z)
}
As it should be clear from the example here -- the idea for this is for a logic programming compiler plugin, and in particular, supporting anonymous top-level rules, rather than having to annotate e.x a top level function or val, which we would then have to name.
I guess the other option would to be use something like:
Copy code
@Target(AnnotationTarget.EXPRESSION)
annotation class Rule
and then have the compiler plugin look for top-level Rule expressions, parse them, and apply it's own logic to them before removing them from the raw input that is passed on to the rest of the Kotlin compiler (which would not accept such top-level unassigned expressions) But then again, I'm not sure if doing something like this would require language changes, or changes to the compiler plugin API.
r
yes, a compiler plugin would allow you to evaluate those at compile time and transform them if you want but when it comes to persistence and serialization once you’ve done your analysis you would still have to turn those into Strings or whatever typed value annotations support.
if you want to evaluate the functions after compilation then you would have to read them and turn them back into a data structure or representation you can run.