是否可以在atom IDE中将1行代码分成多行,就像在Rstudio中一样

发布于 2025-01-12 19:36:43 字数 231 浏览 1 评论 0原文

我对使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骷髅 2025-01-19 19:36:43

是的。该方法根据代码行包含的内容或具体要断行的位置而有所不同。

对于像您在问题中发布的字符串,您必须在换行符之前添加 \ 字符,以通知 Julia 您使用此换行符只是为了提高可读性,并且不希望使用它包含在实际字符串中。 (注意:我将使用具有 julia> 提示符的命令行 REPL 来说明这些内容,但相同的原则也适用于基于 Atom/VS Code 的 IDE 设置)。

julia> println("Hello \
       world")
Hello world

在字符串之外,如果当前行不完整,Julia 会自动在下一行中查找延续。这意味着要将一行分成多行,您必须保留除最后一行之外的所有行:


julia> 1 + 
       2 + 
       3 * 
       4
15

julia> DEPOT_PATH |>
       first |> 
       readdir
16-element Vector{String}:
 "artifacts"
 "bin"
  ⋮

julia> 1,
       2,
       3
(1, 2, 3)

在某些情况下,当您没有方便的二元运算符来像上面那样挂起时,您可能必须以左括号,以便 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 the julia> prompt, but the same principles apply in the Atom/VS Code based IDE setups too).

julia> println("Hello \
       world")
Hello world

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:


julia> 1 + 
       2 + 
       3 * 
       4
15

julia> DEPOT_PATH |>
       first |> 
       readdir
16-element Vector{String}:
 "artifacts"
 "bin"
  ⋮

julia> 1,
       2,
       3
(1, 2, 3)

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.

浪漫之都 2025-01-19 19:36:43

您还有由 """ 表示的多行 String

julia> println("""This
       is
       a multi-line \
       text""")
This
is
a multi-line text

You also have multi-line Strings denoted by """:

julia> println("""This
       is
       a multi-line \
       text""")
This
is
a multi-line text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文