[Idea] Allow specifying aliases for stateful functions in annotation
Opened this issue · 0 comments
This is sort of an elaboration on the earlier principle where we would also register a "clojurized" name for a stateful function but it goes beyond that and makes it user configurable.
Basic idea
Allow users to specify the name(s) with which a stateful function should be registered.
Like so:
public class C {
@defsfn( names = {"my-func"} )
public Object m(...) {}
}
Concrete semantics
Then the names
field is present the stateful function will no longer be registered with its method name ("m"
in this case) which allows users to create multiple stateful functions with the same method name without colliding.
Alternatively the names
value can be left empty which will result in the method name being registered with the linker, this ensures this change is backwards compatible.
The names
value should be of type String[]
to allow multiple aliases for this function to be created.
public class C {
@defsfn( names = {"my-func", "alternativeName"} )
public Object m(...) {}
}
This means that users which prefer clojure-like function names are now free to use those.
public class C {
@defsfn( names = {"="} )
public Object sfnEquals(Object o1, Object o2) {
return o1.equals(o2)
}
}
Name restrictions
It is tricky to decide what a valid name should be.
We might either want to not allow anything which is prohibited in clojure code, however users may want to use a different frontend in which case some of those characters may be valid again.
I therefore propose not to add character restrictions as of yet but have the linker for the clojure frontend emit a warning if it encounters a stateful function with an unusable name.