LUA Functional Programming Demo

Source: Internet
Author: User
What is functional programming

Http://www.zhihu.com/topic/19585411/hot

The nature of functional programming
Functions in functional programming the term does not refer to a function in a computer (actually a subroutine), but rather to a function in mathematics, the mapping of an independent variable. This means that the value of a function is determined only by the value of the function parameter, not by other states. For example, the sqrt (x) function calculates the square root of X, as long as x is not changed, and whenever the call is called, the value is constant.
In a functional language, a function can be defined anywhere, within a function or function, as a function's parameter and return value, and can be combined with a function.
Heart Court
Links: http://www.zhihu.com/question/28292740/answer/40336090
Source: Know
Copyright belongs to the author, please contact the author for authorization.

Example

function Makeenscapehandler (func, preprocess)

return function (num)

num = preprocess (num)

Func (NUM)

End

End

Local function plusonefunc (num)

Return num+1

End

Local Printplusone = Makeenscapehandler (print, Plusonefunc)

Printplusone (1)

LUA Functional Programming Demo

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.