diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt index 9743363c6..ab9ff0e72 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt @@ -3,7 +3,6 @@ package kscience.kmath.expressions import kscience.kmath.operations.Algebra import kotlin.jvm.JvmName import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty /** * A marker interface for a symbol. A symbol mus have an identity @@ -85,11 +84,16 @@ public interface ExpressionAlgebra : Algebra { public fun ExpressionAlgebra.bind(symbol: Symbol): E = bindOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") -public val symbol: ReadOnlyProperty = object : ReadOnlyProperty { - override fun getValue(thisRef: Any?, property: KProperty<*>): StringSymbol = StringSymbol(property.name) +/** + * A delegate to create a symbol with a string identity in this scope + */ +public val symbol: ReadOnlyProperty = ReadOnlyProperty { thisRef, property -> + StringSymbol(property.name) } -public fun ExpressionAlgebra.binding(): ReadOnlyProperty = - ReadOnlyProperty { _, property -> - bind(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist") - } \ No newline at end of file +/** + * Bind a symbol by name inside the [ExpressionAlgebra] + */ +public fun ExpressionAlgebra.binding(): ReadOnlyProperty = ReadOnlyProperty { _, property -> + bind(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist") +} \ No newline at end of file