This is an incomplete answer
I was able to do some progress using the suggestions from @MarcoB.
For example, using this:
Flatten[Names[#] & /@ {"$0*", "$1*", "$2*", "$3*", "$4*", "$5*", "$6*", "$7*", "$8*", "$9*", "$A*", "$B*", "$C*", "$D*", "$E*", "$F*", "$G*", "$H*", "$I*", "$J*", "$K*", "$L*", "$M*", "$N*", "$O*", "$P*", "$Q*", "$R*", "$S*", "$T*", "$U*", "$V*", "$W*", "$X*", "$Y*", "$Z*", "$a*", "$b*", "$c*", "$d*", "$e*", "$f*", "$g*", "$h*", "$i*", "$j*", "$k*", "$l*", "$m*", "$n*", "$o*", "$p*", "$q*", "$r*", "$s*", "$t*", "$u*", "$v*", "$w*", "$x*", "$y*", "$z*", "0*", "1*", "2*", "3*", "4*", "5*", "6*", "7*", "8*", "9*", "A*", "B*", "C*", "D*", "E*", "F*", "G*", "H*", "I*", "J*", "K*", "L*", "M*", "N*", "O*", "P*", "Q*", "R*", "S*", "T*", "U*", "V*", "W*", "X*", "Y*", "Z*", "a*", "b*", "c*", "d*", "e*", "f*", "g*", "h*", "i*", "j*", "k*", "l*", "m*", "n*", "o*", "p*", "q*", "r*", "s*", "t*", "u*", "v*", "w*", "x*", "y*", "z*"}]
We can get the name of all possible functions on Mathematica.
From the Kotlin side, we can transform any iterable object to a "Mathematica List" (this case transforming to a compatible string). This extension will be available to any iterable:
/**
* Transform an iterable object to a Mathematica List.
*/
fun Iterable<Any>.toMathematicaList(): String {
var result = "{"
this.iterator().forEach {
result += when (it) {
is Number -> "$it, "
else -> "\"$it\", "
}
}
// Dropping the remaining `, `.
result = result.dropLast(2)
result += "}"
return result
}
fun main() {
println(arrayListOf("1", 2, 3.1415, "3", arrayOf(1, 2, 3)).toMathematicaList())
}
// Outputs: {"1", 2, "3", 3.1415, "[Ljava.lang.Integer;@1a6c5a9e"}
// As we can see a more complex object was not transformed because of the toString() method. But we still can handle it later, if needed.
// But the format is the format of what Mathematica expects for a List and the number 2 and 3.1415, remain numbers.
I'm needing a way to get all possible arguments the functions can receive in a way that I could parse them. For example, if it receives a List, I'd like to create a function override that will receive a List as one of its arguments. For simplicity we can consider only the InputForm from Mathematica for now. Does someone knows how can we do that?
Example of function generations:
/**
*
*/
fun `$ActivationGroupID`(): String {
}
/**
*
*/
fun `$ActivationKey`(): String {
}
/**
*
*/
fun `$ActivationUserRegistered`(): String {
}
With the backticks (`) we can escape the $
in the function names, when in Kotlin.
An excerpt of how I imagine it could work (maybe not all parts would be easy, but seems possible, please confront with the Range documentation):
import java.lang.IllegalArgumentException
/**
*
*/
fun main() {
val range1 = Range(10)!!
val range2 = Range(10, 20)
val range3 = Range(10, 20, 2)
for (i in range1) {
print(i)
}
}
/**
*
*/
class Mathematica {
/**
*
*/
fun evaluateToInputForm(expression: String?): String? {
if (expression == null) throw IllegalArgumentException("Invalid expression.")
// ... code that calls Mathematica here.
val output: String? = null
return output
}
/**
*
*/
inline fun <reified Return> extract(rawResult: String?): Return? {
if (rawResult == null) return null
// A special code is needed here.
return rawResult as Return?
}
/**
*
*/
inline fun <reified Return> evaluateAndExtract(expression: String?): Return? {
val rawResult = evaluateToInputForm(expression)
return extract<Return>(rawResult)
}
}
val mathematica = Mathematica()
open class MathematicaObject{}
abstract class Range : MathematicaObject(), List<Number>
/**
* Generates the list {1,2,\[Ellipsis],Subscript[i, max]}.
* Generates the list {Subscript[i, min],\[Ellipsis],Subscript[i, max]}.
* Uses step di.
*/
fun Range(iMax: Int): Range? {
return mathematica.evaluateAndExtract<Range>("Range[$iMax]")
}
/**
* Generates the list {1,2,\[Ellipsis],Subscript[i, max]}.
* Generates the list {Subscript[i, min],\[Ellipsis],Subscript[i, max]}.
* Uses step di.
*/
fun Range(iMin: Int, iMax: Int): Range? {
return mathematica.evaluateAndExtract<Range>("Range[$iMin, $iMax]")
}
/**
* Generates the list {1,2,\[Ellipsis],Subscript[i, max]}.
* Generates the list {Subscript[i, min],\[Ellipsis],Subscript[i, max]}.
* Uses step di.
*/
fun Range(iMin: Int, iMax: Int, di: Int): Range? {
return mathematica.evaluateAndExtract<Range>("Range[$iMin, $iMax, $di]")
}
If we get a list of all French words, and a dictionary with their definitions, then it should be easy to speak French
. $\endgroup$