Julia

Julia 中的函数是将一系列参数组成的元组映设到一个返回值的对象

Julia 中定义函数的基本语法为:

julia> function f(x, y)
       x + y
       end
f (generic function with 1 method)

该函数等价的赋值形式

f(x, y) = x + y

调用该函数

julia> function f(x, y)
       x + y
       end
f (generic function with 1 method)

julia> f(2, 3)
5

f 指向的是函数对象,该函数对象赋值给其他变量

julia> g = f
f (generic function with 1 method)

julia> g(2, 3)
5

早些版本还有一种调用函数的方法

apply 函数把第一个参数当做函数对象,后面的参数是该函数对象的参数

julia> apply(f,2,3)
5

变量名也可以使用 Unicode 字符

julia> function 你好(x, y)
       x + y
       end
你好 (generic function with 1 method)

julia> 你好(2, 3)
5
原文地址:https://www.cnblogs.com/sch01ar/p/9506536.html