Visual Basic 9.0 cutting-edge broadcast-static (4) nested functions and Closure

Source: Internet
Author: User
To support the query features supported by the Linq platform, VB9 must introduce a small number of functional programming (FP) features. The nested functions and Closue features introduced in this article are the most important part. Before discussing why such features are introduced, let's take a look at the features. VB9 allows Define functions or subprograms in the processSuch:
 Public Sub MyProc()Sub MyProc()Sub Nested()Sub Nested()'Code here    End SubEnd Sub
The first purpose that can be considered is that a helper function can be used only for a specific process, and nested functions defined in this process cannot be accessed outside the process. This is similar to nested functions in Delphi. Note that nested functions can only be accessed in the context after definition. The following is the biggest difference between nested functions and traditional functions:
 Public Sub MyProc()Sub MyProc()Dim x As IntegerSub Nested()Sub Nested(i As Integer)        x = iEnd Sub'Invoke subroutine    Nested(20)    Console.WriteLine(x);End Sub

Nested functions can access variables in external processes. This feature is calledClosure. With Closure, we can generate functions with variable rules to achieve latency computing. This is a basic function of FP. Closure, an embedded function of VB9, may be implemented by using the Tuple feature. However, there is no further computing on the principle. Compared with C # anonymous functions, VB9 embedded functions have two main advantages:

1. It can be called repeatedly without being delegated. You can obtain it through AddressOf when you need to delegate.
2. Direct recursion is supported. (Of course, the master can use the Y operator. Let's talk about it later ......)

Visual Basic also considers adding the expression of anonymous embedded functions, which is well known.Lambda expressions. However, no syntax is provided, so I will not introduce it first.

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.