Some features of the LUA approach--lua and Android

Source: Internet
Author: User

Learning Lua has to understand its methods or grammatical characteristics, such as:
Multi-value return

function Maximum (a)     1 -- maximum index    = A[mi]-- maximum value    for        if val > m            then = I            = val        end    End  Return  m, miend

Print (Maximum ({8,10,23,12,5}))--23 3

Variable parameters

function g (A, B, ...) End or function g (...) Endcall             PARAMETERSG (3)              a=3, B=nil, arg={n=0}g (34)          a= 3, b=4, arg={n=0}g (3458)   a=3, b=4, arg={58; n=2}

Tail call

It feels like recursion, recursion is calling itself, the function of tail call tune is not necessarily self

feel like recursion, recursion is called itself, the function of tail call tune is not necessarily self function foo (n)     if 0 return 1 ) endendfunction f (x)    // do something at x    return  g (x) End 
Advantages:
The tail call does not need to use the stack space (itself stack control), then the tail call recursive hierarchy can be unrestricted, without worrying about stack overflow. These are not tail calls:
function f (x)     // not a tail call    return return function    return1do      The addition     return 1 result     return 1 Resultend

Some features of the LUA approach--lua and Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.