Is the closure in discrete mathematics related to the closure in computer languages?

Source: Internet
Author: User
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply: based on Wikipedia entries (http://en.wikipedia.org/wiki/Closure_ (computer_science) # History_and_etymology), especially annotations 4, 5, and 6. we can see that the clourse usage in computer languages was invented by P. J. Landin, which means closed expression. That is, the result of the closed bindings (free variables) in the lambda expression.

There is no evidence that the term created by Landin is directly related to the concept of closure in mathematics.@ Ivony I think it is only because the two use the same word, so it must be related to the meaning of the word close. There is no relationship between the half points. Chapter 2 of the model is described as follows:

The use of the word ''closure ''here comes from abstract algebra, where a set of elements is said to be closed under an operation if applying the operation to elements in the set produces an element that is again an element of the set. the Lisp community also (unfortunately) uses the word ''closure ''to describe A totally unrelated concept: A closure is an implementation technique for representing procedures with free variables. the contact is not clear.

Zhu Zhaolong's kids shoes mix closure and closure:
In discrete mathematics (specifically abstract algebra), if an operation is performed on each element in a set, the result is still the element of the set, the set constitutes a closure under this operation. For example, an integer set forms a closure under the subtraction operation, but a natural number does not constitute a closure under the subtraction operation.
If each element in a set executes an operation or an element in the set, the set is under this operation. Close.

The closure is defined, IncludeThe specified set meets a certain operation. CloseOf Minimum set.


To put it bluntly, the closure is to add the least element so that the set is closed under a certain operation. Abstract, A closure refers to adding something to make it true..

So what is the closure in the programming language? The function uses variables outside the function. if the variables outside the function are not global variables, they are automatically created. ClosureSo that the variables used by the internal function exist together with the function, MakeThis function is valid.

That is to say ClosureThis is to automatically add an invisible parameter to this function. its value is the used external variable and it must exist together with the function to make the function effective. Simply put, these two concepts are almost unrelated (maybe, but I didn't find them ). I will briefly explain the meanings of the two closures in two fields:
1. in Discrete Mathematics (specifically abstract algebra), if an operation is performed on each element in a set, the result is still the element of the set, the set constitutes a closure under this operation. For example, an integer set forms a closure under the subtraction operation, but a natural number does not constitute a closure under the subtraction operation.
2. in programming languages, it is also called lexical closure or function closure. it represents a function, and an environment that defines this function (the environment records the values of non-local variables ). For example, the horizontal line is for alignment ):
Def counter ():
---- X = 0
---- Def increment (y ):
-------- Nonlocal x
-------- X + = y
-------- Print (x)
---- Return increment
This example uses the syntax of python 3.x. it has always felt that the implementation of python closures is not as beautiful as that of lisp and ruby.
Reference:
1, http://en.wikipedia.org/wiki/Closure_ (computer_science)
Http://en.wikipedia.org/wiki/Closure_ (mathematics) Closure in discrete mathematics

1. @ Ivony's statement is the same as that of the textbook used by our school. "It contains the minimum set that satisfies the closure of a specific operation ", closure is a set of conditions.

2. another statement is from Wikipedia. if the result of A certain operation in set A still belongs to set A, it is assumed that set A has the closure attribute in this operation. It can also be said that set A is closed in this operation.

In the first statement, closure and closure do not have the same meaning. In the second statement, closure and closure are only the differences between nouns and adjectives.

Closures in programming languages

It is also called the lexical closure or function closure. it refers to the features in the program language. The program language with this feature can use the environment where the functions and functions are located as a whole. Sometimes this is called a closure.

We recommend that you use the closure and function closure in the future. Otherwise, a misunderstanding may occur. I don't want to raise this question, but the closure mentioned in discretization is the same as the closure of the function and can be considered as an equivalent proposition.

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.