Python-like decorator annotation? #17867
Replies: 0 comments 2 replies
-
If you replace a def with a val you:
Not to mention you cannot do it for defs with default parameters or repeated arguments. So I don't think having code that uses "def" but actually behaves as if it was a val is a good idea, it's already hard enough for people to understand the difference between these two concepts without complicating things further. But the basic idea of having macros that transform code existed in Scala 2 as macro annotations and that might be brought back in a more controlled form in Scala 3. |
Beta Was this translation helpful? Give feedback.
-
Alright, the idea was that defs would be altered and still compiled to defs before runtime, so no vals, more like a macro annotation that is controlled, and if that is coming in such a way, i suppose code transformation like this would be possible without a special case. |
Beta Was this translation helpful? Give feedback.
-
With the compile-time inline functions we have nowadays, a decorator system could be implemented.
This would make
def
declarations more readable and more reusable, without having to transform it into a function val.I don't know how the
this
could be passed, maybe as a given in the decorator. Context functions and Polymorphic functions would make this quite elegant.Beta Was this translation helpful? Give feedback.
All reactions