A kid’s dilemma: writing simple programs in kotlin...
# getting-started
m
A kid’s dilemma: writing simple programs in kotlin with user input and a custom set of inline functions for statements localization. Is it even possible in an IDE? Hi everyone! 🙂 I’d like to help my kid who’s willing to learn to code. I’d like to teach him Kotlin since it’s the best language ever but I just can’t find a way to have an IDE for interactive console scripts and importing some extension functions. I’d love to give him the chance to write simple programs and run them interactively, so he can do the usual basic stuff like asking the user for the age and then print it back, or double it and print it back. I’d also really like him to be able to write those programs using Italian instructions and not English ones. Basically because he asked me to do so, since he just learnt to read and write italian and it’s much easier for him to learn simple commands when he knows the meaning of them. I know that Kotlin Script works for the first part and I managed to configure Intellij Idea for this simple task: write a simple script with
readline
and
println
and run it (see the first picture). Now the second part: I wrote (with a little help from a neighbour AI) a set of extension functions meant to override the basic instructions of the language with italian ones (see the second picture below). These extensions work fine in a kotlin standard environment and I was able to write some short funny programs (see the third picture). I’m not able to import these extension functions in the kotlin script though, so at the moment I’m stuck because it seems to me I have to choose between • having a standard kotlin environment, no readln() and no standard input from the user if I’m using a IDE (and I’d like to, because of autocompletion and stuff) but I get the benefits of the extension functions in italian • using kotlin script, I can read from user’s input in the console of the IDE but I can’t import the extension functions It hurts me, since I like the scripting part and I love the old school text-only interaction with the user, but I don’t want to be limited to have everything in a single file, since I’d like to teach him about functions as well and I don’t want things to get bloated. Do you happen to have any suggestion for a frustrated father? 🙂 Thank you Marco
❤️ 2
e
having a standard kotlin environment, no readln() and no standard input from the user if I’m using a IDE (and I’d like to, because of autocompletion and stuff) but I get the benefits of the extension functions in italian
What problem are you facing with
readln
when running a
main
function?
It works fine in my IDE
h
I don’t know if Kotlin Notebook supports readline but it also allows you to simply show outputs like pictures.
m
@edrd you’re right, it works. Yesterday I simply was not able to have the input prompt displayed in the “run” section of the IDE, now I opened IDEA again from scratch and… it worked -.- I guess I stumbled upon a bug, I didn’t turn-it-off-and-then-back on, so silly of me.
🙏 1
I guess I’m done, with a standard kotlin environment now I can use readln and also the extensions 🙂 Hurray! I’d still leave the post here in case anybody in the future should have the same no-prompt issue, or should the localized extensions idea be useful for anyone.
kodee excited 1
k
A quick note on terminology: I don't see any extension functions, just normal inline functions (using Italian equivalents of common function names, and also for "if" and "else"). Extension functions are those that have an implicit receiver. I was initially a bit confused.
1
m
You’re right @Klitos Kyriacou, I got confused. It’s all inline functions re-mapping the usual statements.