;结束后,它对性能产生什么影响?

发布于 2025-02-08 16:39:25 字数 307 浏览 0 评论 0原文

       function fill_twos!(a)
           for i = eachindex(a)
               a[i] = 2
           end
       end;

函数来自 julia doc 它也可以在结构之后的某些地方使用

       function fill_twos!(a)
           for i = eachindex(a)
               a[i] = 2
           end
       end;

function from JULIA DOC
It is also available in some places after Struct

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蘑菇王子 2025-02-15 16:39:25

;对性能没有任何影响。 Julia手册中的示例代码仅使用它来减少代码段中的不必要输出。

通常,无论您在复制中输入什么代码,它的结果都会由REPL打印出来。如果您希望您的代码得到评估,但结果未打印出来,则可以在其结尾处添加半隆。

julia> x = pi
π = 3.1415926535897...

julia> x = pi;

以上行将pi的值分配给x,但是第二个线路不打印该评估的结果,因为它以半决赛结束。同样,当您在repl中输入功能时:

julia> function fill_twos!(a)
         for i = eachindex(a)
           a[i] = 2
         end
       end
fill_twos! (generic function with 1 method)

最后一行是定义函数的输出。在示例代码段中,如果为每个函数/方法定义打印出来,这将是占用额外空间的混乱。因此,他们使用分号抑制输出。

它对函数执行的性能或任何其他方面没有影响。

The ; doesn't have any effect on performance. The example code in the Julia manual uses it only to reduce unnecessary output in the code segments.

Normally, whatever code you type in the REPL, the result of it gets printed by the REPL. If you want your code to get evaluated, but its result not be printed out, you can add a semicolon at the end of it.

julia> x = pi
π = 3.1415926535897...

julia> x = pi;

Both the above lines assign the value of pi to x, but the second one doesn't print the result of that evaluation because it ends in a semicolon. Similarly, when you type out a function in the REPL:

julia> function fill_twos!(a)
         for i = eachindex(a)
           a[i] = 2
         end
       end
fill_twos! (generic function with 1 method)

That last line is the output from defining your function. In the example code segments, this would just be clutter that takes up extra space, if it was printed out for every function/method definition. And so, they're suppressing that output using the semicolon.

It has no effect on performance or any other aspect of the function execution.

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