GarouDan
06/10/2020, 11:50 PM!
(in the end), /.
, @
, ->
and also create lists in this way {1, "2", a}
, instead of listOf(1, "2", a)
.
I’d like to mimic as much as possible the Mathematica language in Kotlin. A valid Mathematica code is:
N[
D[
Normal[
Series[
Integrate[
Zeta[x],
x
],
{x, 0, 6}
]
],
{x, 2}
] /.x -> 15,
10
]
and in Kotlin, I’d like to run something like this:
val x = "x"
n(
d(
normal(
series(
integrate(
zeta(x),
x
),
{x, 0, 6}
)
),
{x, 2}
) /. x -> 15,
10
)!
Where the n
, d
, normal
, etc., objects have a special toString
method, and /.
binary operator would do something with the previous and next argument and the ->
would be another binary operator. In some way, these binary operators are similar to +
and -
binary operators.
At the moment the following works in Kotlin:
val x = "x"
!n(
d(
normal(
series(
integrate(
zeta(x),
x
),
listOf(x, 0, 6)
)
),
listOf(x, 2)
) + "/. $x -> 15",
10
)
Also, a lot of different operators would be hopefully needed since it is used in this grammar, like the @
, @@
, etc.
So the proposal is have the possibility to create the /.
, ->
, @
, @@
and other operators (to mimic the grammar) and also create lists in this way {1, "2", a}
, instead of using listOf(1, "2", a)
.louiscad
06/11/2020, 6:29 AMelizarov
06/11/2020, 7:21 AMraulraja
06/11/2020, 9:02 AMnot
in prefix position. If you don’t mind the !
in prefix this should work:
class MyClass {
operator fun not() {
println("finished")
}
}
fun main() = !MyClass()
raulraja
06/11/2020, 9:04 AM!
as an invoke operator is used in some langs and papers and may suit a DSL. not
is not constrained to Boolean expressions and same goes for +
and others that you may override at will https://kotlinlang.org/docs/reference/operator-overloading.html each one of them with their own restrictions.louiscad
06/11/2020, 9:30 AMlouiscad
06/11/2020, 9:32 AMnot()
a lot more than !
because it's more noticeable, and helps to avoid bugs of inverted condition.raulraja
06/11/2020, 9:40 AMMyClass()
but there is not enough context in the message to understand the purpose of the DSL.GarouDan
06/11/2020, 11:12 AMn
, d
, normal
, are very common there.louiscad
06/11/2020, 11:21 AM!
a shortcut to call an an external program? To me, that should just be a function call, nothing extra. The fact it is external is mostly an implementation detail.
To me, it's not obvious at all what a suffix like !
would and should do. The limitation "against" custom arbitrary operators and unobvious non explicit things is one of Kotlin's greatest strenght, one that makes us all able to read and understand one another code, and able to trust it once understood. Kotlin's basics are simple despite several unique powerful features like extensions/receivers and coroutines. Many things can be done with just functions and standard operators.
Maybe you can be more specific as to what the difference would be in your specific case between with and without the !
suffix? I think that'll help us suggest a more idiomatic solution.GarouDan
06/11/2020, 11:25 AMrun
, runTo
, etc methods that I can call. It is just I’d like to have as much closer to this as possible:
N[
D[
Normal[
Series[
Integrate[
Zeta[x],
x
],
{x, 0, 6}
]
],
{x, 2}
] /.x -> 15,
10
]
because this is the valid Mathematica code.louiscad
06/11/2020, 11:30 AM!
in there.
BTW, if you really cannot stand the listOf
, you can use a vararg
, which is convenient until the number of arguments can vary at runtime or comes from a collection.GarouDan
06/11/2020, 11:33 AMGarouDan
06/11/2020, 11:35 AM/.
one, this would be very nice, also the ->
louiscad
06/11/2020, 11:37 AMGarouDan
06/11/2020, 11:39 AMGarouDan
06/11/2020, 11:50 AMlouiscad
06/11/2020, 11:54 AMraulraja
06/11/2020, 12:38 PMGarouDan
06/11/2020, 12:56 PM/
div operator should be different from /.
one, but I got the idea. Unfortunately we cannot create operators with special symbols.
I’ve created these issues here:
https://youtrack.jetbrains.com/issue/KT-39539
https://youtrack.jetbrains.com/issue/KT-39538louiscad
06/11/2020, 1:08 PM/.
operator and what is it supposed to do?raulraja
06/11/2020, 1:09 PMGarouDan
06/11/2020, 1:10 PMraulraja
06/11/2020, 1:10 PMlouiscad
06/11/2020, 1:11 PMreplaceAll
then? It's more explicit, no need to explain it, and now way you first think it means "special division" (that was my first thought).GarouDan
06/11/2020, 1:12 PM@
, @@
we don’t have too much possibilities.GarouDan
06/11/2020, 1:12 PMlouiscad
06/11/2020, 1:13 PMGarouDan
06/11/2020, 1:15 PMGarouDan
06/11/2020, 1:18 PMGarouDan
06/11/2020, 1:21 PMlouiscad
06/11/2020, 2:06 PMGarouDan
06/11/2020, 4:28 PM