是否可以在atom IDE中将1行代码分成多行,就像在Rstudio中一样
我对使用 Julia 和 Atom IDE 很陌生,我想知道是否有可能以某种方式只按 Enter 键并让计算机运行分散在多行中的 1 行代码,并且仍然让它认识到它仍然是相同的 1一行代码,就像在 Rstudio 中一样? (我希望这只是出于可读性目的)
我的意思是这样的:
println("Hello
world")
并且能够突出显示并运行此脚本而不会收到错误消息。
I am new to using Julia and the atom IDE, and I was wondering if it was possible to somehow just press enter and have the computer run 1 line of code spread over multiple lines, and still have it recognize that it is still the same 1 line of code, just like in Rstudio? (I want this for readability purposes only)
what I mean is something like:
println("Hello
world")
and be able to highlight and run this script without receiving an error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。该方法根据代码行包含的内容或具体要断行的位置而有所不同。
对于像您在问题中发布的字符串,您必须在换行符之前添加
\
字符,以通知 Julia 您使用此换行符只是为了提高可读性,并且不希望使用它包含在实际字符串中。 (注意:我将使用具有julia> 提示符的命令行 REPL 来说明这些内容,但相同的原则也适用于基于 Atom/VS Code 的 IDE 设置)。
在字符串之外,如果当前行不完整,Julia 会自动在下一行中查找延续。这意味着要将一行分成多行,您必须保留除最后一行之外的所有行:
在某些情况下,当您没有方便的二元运算符来像上面那样挂起时,您可能必须以左括号,以便 Julia 知道这是一个连续语句,直到遇到右括号。
Yes. The method differs based on what the line of code contains, or specifically, where you want to break the line.
For a string like you've posted in the question, you have to precede the newline with a
\
character, to inform Julia that you're using this newline only for readability, and don't want it to be included in the actual string. (Note: I'll be illustrating these with the command-line REPL that has thejulia>
prompt, but the same principles apply in the Atom/VS Code based IDE setups too).Outside of strings, if the current line isn't complete, Julia automatically looks for the continuation in the next line. This means that to break a line into multiple ones, you have to leave all but the final line incomplete:
In some cases when you don't have a convenient binary operator to leave hanging like the above, you may have to start your line with an opening parenthesis, so that Julia will know that it's a continuous statement until the closing parenthesis is encountered.
您还有由
"""
表示的多行String
:You also have multi-line
String
s denoted by"""
: