zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    3.22
    练习 3.16
    简单工厂模式
    Java-不可变字符串
    java中的缓冲流
    TCP协议下java通信
    nginx优化
    nginx反向代理
    shell-for循环
    shell-数组
  • 原文地址:https://www.cnblogs.com/sch01ar/p/9506536.html
Copyright © 2011-2022 走看看