zoukankan      html  css  js  c++  java
  • Functions & Closures

    Functions

    1、不带返回值的函数:

      

    2、通过tuple返回元素

      

      返回的tuple可按如下方式使用:

      

    3、External Parameter:

      

      External parameter的使用:

        

    4、Shorthand external parameter:

      

    5、Default Parameter:

      

      Default Parameter自动定义了external parameter:

      

      

    6、Variadic Parameters,变长参数,在类型后面加上...:

      

    7、Variable Parameter,函数参数默认是const,即函数body内无法改变参数值。要想在函数body内改变此值,需用var声明参数。

      

    8、In-out参数:

      

      使用in-out参数:

      

    9、FunctionType:

      

      可以在String Interpolation中调用函数:

      

    10、FuntionType as Parameter Type:

      

    11、FunctionType as Return Type:

      

    Closures

    1、三种Closure:

      

    2、Closure Expression Syntax:

      

      

    3、Inferring Type From Context

      

      在单表达式Closure的情况下,return也可以省略:

      

    4、Shorthand Argument Names,通过数字

      

    5、Operator Function

      

    6、Trailing Closure

      

      array.map使用Trailing Closure的例子:

      

    7、下述代码中,runningTotal会capture reference:

      

    8、Closure are reference types。

  • 相关阅读:
    source命令
    [电脑配置]屏幕扩展过,找不到界面
    [SAS]方便查询Tips
    [Excel]方便查询Tips
    [SAS]运用函数等的一些问题
    [SAS]错误整理
    [SAS]易错例子之数值型转字符型
    [R]Precedence
    [sas]Missing Value
    [SAS]
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3789380.html
Copyright © 2011-2022 走看看