Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在kotlin REPL中粘贴模式/多行代码段?_Kotlin_Paste_Read Eval Print Loop - Fatal编程技术网

在kotlin REPL中粘贴模式/多行代码段?

在kotlin REPL中粘贴模式/多行代码段?,kotlin,paste,read-eval-print-loop,Kotlin,Paste,Read Eval Print Loop,给定函数的骨架: fun reformat( str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ', ) { println("In reformat") } 我将其粘贴到kotlin REPL中,

给定函数的骨架:

fun reformat(
    str: String,
    normalizeCase: Boolean = true,
    upperCaseFirstLetter: Boolean = true,
    divideByCamelHumps: Boolean = false,
    wordSeparator: Char = ' ',
) {
  println("In reformat")
}
我将其粘贴到kotlin REPL中,它抱怨道——显然是因为没有意识到它被发送了一个多行代码片段:

>>> fun reformat(
error: parameter name expected
fun reformat(
             ^
error: expecting comma or ')'
fun reformat(
             ^
error: expecting ')'
fun reformat(
             ^

>>>     str: String,
error: expecting an element
    str: String,
       ^
error: expecting an element
    str: String,
               ^

etc ..

什么是scala REPL中的
:粘贴

看起来Kotlin REPL是从IDE使用的。如果您从Intellij IDEA中打开它,它就像一个符咒,允许您进行多行输入。我没有看到任何选项允许您在常规shell中执行相同的操作。因此,在您的情况下,您可以在一行中声明函数,也可以从文件中加载脚本。

我发现一个项目-显然由JetBrains kotlin开发人员自己积极改进,解决了这个问题和其他问题:。这是他们的帮助

[0] :h
:quit or q                           quit the shell
:load or l <path>                    load file and evaluate
:type or t <expr>                    display the type of an expression without evaluating it
:list or ls                          list defined symbols
:help or h [command]                 print this summary or command-specific help
:paste or p                          enter paste mode
:syntax {on | off}                   syntax highlighting
:prompt [pattern]                    customize prompt
:set                                 set configuration parameter
:conf                                list configuration parameters
:dependsOn <artifact coordinates>    Load dependency from the current set of repositories
:repository <repository coordinates> Add repository for the artifacts lookup
:classpath or cp                     Show current script compilation classpath

这正是我想要的。它确实可以工作(尽管有丑陋的JDK9警告):


哇,那真是个糟糕的家伙。我是JetBrains的狂热爱好者(从2008年开始),但有时我只是不想为python(vs Pycharm)或scala(vs IJ)打开IDE的开销
[1] :p
// Entering paste mode (ctrl-D to finish)

[1] :p
// Entering paste mode (ctrl-D to finish)
fun reformat(
    str: String,
    normalizeCase: Boolean = true,
    upperCaseFirstLetter: Boolean = true,
    divideByCamelHumps: Boolean = false,
    wordSeparator: Char = ' ',
) {
  println("In reformat")
}

// Exiting paste mode, now interpreting.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jetbrains.kotlin.com.intellij.util.ReflectionUtil (file:/Users/steve/git/kotlin-interactive-shell/ki-shell/target/ki-shell-0.4-SNAPSHOT-shaded.jar) to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
WARNING: Please consider reporting this to the maintainers of org.jetbrains.kotlin.com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[2] reformat()
ERROR No value passed for parameter 'str' (Line_3.kts:1:10)
[3] reformat("abc")
In reformat