Reflection/Get source: Difference between revisions

Added Kotlin
(Added Julia language)
(Added Kotlin)
Line 97:
@which foo() # where foo is defined
@less foo() # first file where foo is defined</lang>
 
=={{header|Kotlin}}==
It's possible to do this (in a fashion) in Kotlin JS by using inline JavaScript and applying toString() to the function name to get its source code in a similar way to the JavaScript entry above. However, there are a couple of things to note:
 
1. Kotlin JS transpiles to JavaScript and it will therefore be the JS code for the function which will be printed. To my knowledge, there is no way to recover the original Kotlin code.
 
2. In the example below the ''hello'' function will actually be referred to as ''_.hello'' in the generated JavaScript from within the main() function.
<lang scala>// Kotlin JS Version 1.2.31
 
fun hello() {
println("Hello")
}
 
fun main(args: Array<String>) {
val code = js("_.hello.toString()")
println(code)
}
</lang>
 
{{out}}
<pre>
function hello() {
println('Hello');
}
</pre>
 
=={{header|Lingo}}==
9,476

edits