I have created several DSL frameworks in Kotlin be...
# language-proposals
v
I have created several DSL frameworks in Kotlin before, and often came to situations where I wanted to overload the assignment “=” operator. I know the reason why the Kotlin team is so reluctant to provide this feature because it could be greatly misused. Can I suggest an alternative? Instead of “=”, Kotlin provides a new operator called “:=“, which has no intrinsic meaning unless you explicitly define an operator function for it. The name of this operator function can be called “assign” or “colonAssign”.
☝️ 1
e
v
I have tried the plugin. I doesn’t work. Any more information on how to use it?
e
from the command-line,
Copy code
package fqdn

annotation class SupportsKotlinAssignmentOverloading

@SupportsKotlinAssignmentOverloading
class Settable<T>(var value: T)

fun <T> Settable<T>.assign(value: T) {
    this.value = value
}
Copy code
$KOTLIN_HOME/bin/kotlinc-jvm -Xplugin=$KOTLIN_HOME/lib/assignment-compiler-plugin.jar -P plugin:org.jetbrains.kotlin.assignment:annotation=fqdn.SupportsKotlinAssignmentOverloading ...
(you can see all the strings in https://github.com/JetBrains/kotlin/blob/master/plugins/assign-plugin/assign-plugin.common/src/org/jetbrains/kotlin/assignment/plugin/AssignmentPluginNames.kt)
🙏 1
a
Agree with this a lot, there's been several times w/ DSLs where I find it to be useful to overload =. The assignment plugin seems cool, but I couldn't find a lot of documentation on how to use it
e
@asdf asdf It would be great if you add use-cases with your DSLs to the KEEP.