Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use lambda expressions in Clippers 11

Shulou Source: shulou.com Published: 2022-06-02 08:03:03 09月27日 Update

This article shows you how to use lambda expressions in Clover 11. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

First of all, this lambda is the Roman letter λ, and the lambda expression is the λ expression. In mathematics, there is a concept called λ calculus, one of which is λ expression.

Consider the common representation of mathematical functions:

F (x) = 2x + 1

According to the rules of λ expression, it can be written as follows:

λ x. (2x+1)

This expression can be read as "for the parameter x _ 2x _ 1. Here Lambda, λ, only expresses the concept of" function "in mathematics.

Various programming languages have also introduced λ (lambda) expressions. For example:

C # language: (X) = > {return 2xroom1;}

Java language: (X)-> {return 2xroom1;}

Lambada expressions have also been introduced in Clippers 11.

[] (int x)-> int {return 2 * x + 1;}

For programmers, lambda expressions provide a way to implement unnamed functions.

Nameless annoyance

Lambda expressions do not need to define a function (name), which is a convenience in most scenarios, but it can also cause some annoyance, such as recursive calls. Because there is no function name, how to call yourself becomes a problem.

Of course, this problem can be solved. Here, take the factorial as an example, and go directly to the code:

Function factorial =

[&] (int n) {

If (n < 2) return 1

Return n * factorial (n-1)

}

Cout

Tags: Expressions functions content parameters that is mathematics language recursion annoyance skills methods concepts knowledge types problems ordinary concise consistent concise code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Microsoft MariaDB Shulou Information