Julia中使用function、let、begin定义函数是否存在差异?
Julia中三种函数定义方式是否存在差异?
以下是三种不同写法的Julia函数定义,它们之间是否有区别?
- 使用
function关键字定义:
function g1(x) # compute something, store it in `result` return result # (return keyword is optional) end
- 使用
let关键字定义:
g2(x) = let # compute something, store it in `result` return result # (return keyword is optional) end
- 使用
begin关键字定义:
g3(x) = begin # compute something, store it in `result` return result # (return keyword is optional) end
结论:这三种函数定义方式完全等价
内容的提问来源于stack exchange,提问作者Olivier Verdier
相关产品推荐
相关产品推荐

