Julia中的函数定义
问题描述:
Julia具体具有函数定义吗?如果是,BNF是什么?Julia中的函数定义
例如,它有一个函数声明和函数调用了BNF
•Function Declaration
function name (arguments :: type)
#expressions
End
<function> → (function <identifier> (<arguments>) <expressionList> end) |
<identifier>(<arguments>) <expressionList> end
<arguments> → <identifier> :: <type> | (<identifier> :: <type>),arguments>|e
•Function Call
x = sum (12 , y :: Int32)
<funcall> → <identifier> = <identifier> (<parameterList>)
<parameterList> → <parameter> :: <type>, < parameterList> | <parameter> ::<type> | <parameter>, <parameterList>
<parameter> → <identifier> | <element> | e
答
马特B.在评论中提到的,朱莉娅语法不是上下文无关。
如果<...>
是一个有效的函数调用,然后在一般以下是有效的方法定义:
function <...>; (body); end
<...> = (body)
此外,它允许返回类型注释添加到函数调用:
function <...>::ReturnType; (body); end
<...>::ReturnType = (body)
任何数量的where
子句也是允许的,或者代替或者除了返回类型,短期和长形式:
function <...>::ReturnType where T; (body); end
(<...>::ReturnType) where S = (body)
function <...> where T where S; (body); end
<...> where {S, T} = (body)
长,短两种形式的支持某些预选赛:
global function <...>; (body); end
local <...> = (body)
注意,函数调用本身可以有几种形式;例如,其中每一个都是有效的:
x ← y = x + y
function (x ← y)::Int; 10; end
Julia语法不是上下文无关的。请参阅:https://groups.google.com/d/msg/julia-users/LwewtNffleo/f-AqxMulbFwJ –