2017-09-15 59 views
0

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 
+0

Julia語法不是上下文無關的。請參閱:https://groups.google.com/d/msg/julia-users/LwewtNffleo/f-AqxMulbFwJ –

回答

0

馬特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