Is it possible to start the repl (via `kotlin`) wi...
# getting-started
c
Is it possible to start the repl (via
kotlin
) with a script "preloaded"? I can pipe a script in via stdin, but the repl exits immediately. I want to set up a repl that already has some classes imported / values defined.
Alternatively, somehow being able to call
:load
from a kotlin function would also be useful (via reflection or some other means).
c
Have you tried using Kotlin Notebooks?
c
I have not — is that accessible without intellij? I’d ideally like this to work in a terminal
c
Not in the terminal directly, no. It's available in IntelliJ, or in the browser.
In Bash you should be able to do something like
Copy code
function input() {
    echo ":load your_file"
    while true; do
        read line
        echo $line
    done
}

input | kotlin
but that's not great
Also, I recommend using KI instead of the default REPL, but I don't know if it has something to help here
🙏 1
2
c
I’ll take a look, thank you!
h
@CLOVIS Thank you so much, I had no idea KI existed! Also, the blogpost explicitly mentions the feature @conner was looking for: https://blog.jetbrains.com/kotlin/2021/04/ki-the-next-interactive-shell-for-kotlin/#Scriptingsupport
k
By the way, the latest version is at https://github.com/Kotlin/kotlin-interactive-shell and you can download the source and trivially modify it to use the latest version of Kotlin (1.9).
k
I just come across this a few days ago, looks pretty cool:

https://www.youtube.com/watch?v=2PLYlDJPelQ&pp=ygUPa290bGluIG5vdGVib29r