Questions tagged [lambda]

DO NOT USE FOR THE AWS SERVICE (use [aws-lambda] for those questions!) Lambdas are anonymous functions or closures in programming languages such as Lisp, C#, C++, Lua, Python, Ruby, JavaScript, Java, Excel or Google sheets. (Also, lambda expression.)

This term originated with the lambda calculus, a Turing-complete model of computation which uses only functions, called lambda expressions. They are of the form λ<argument name(s)>.<expression>; the point is that occurrences of the argument <argument name(s)> inside the expression <expression> are substituted with the values of the arguments. An example is λx.x, the identity function.

In programming languages such as , , , and , lambda is an operator used to denote anonymous functions or closures, following the usage of lambda calculus. An anonymous function enables definition of a function without binding to an identifier. Lambda expressions are supported in since version 8, in since version 11.

Android does not currently use Java 8, but Android Studio and other IDEs (IntelliJ Idea, etc.) automagically collapses "Closures" (anonymous classes implementing one method) into lambda expressions.

References

29774 questions
15
votes
4 answers

The Little Schemer evens-only*&co

I'm having difficulty understanding what's going on with The Little Schemer's evens-only*&co example on page 145. Here's the code: (define evens-only*&co (lambda (l col) (cond ((null? l) (col '() 1 0)) ((atom? (car l)) (cond …
14
votes
4 answers

Lambda Expression to filter a list of list of items

I have a a list of list of items and I was wondering if someone could help me with a lambda expression to filter this list. Here's what my list looks like: List> myList = ExtractList(); Here's what my Item class looks like: public class…
zSynopsis
  • 4,854
  • 21
  • 69
  • 106
14
votes
5 answers

Functors when should I use them whats their intended use

I Just can't seem to wrap my head around them. As I understand it's dynamically adding logic to a class. Are classes within the framework prepared for this? Why should I just extend the class and add the functionality to it in the extension. I would…
albertjan
  • 7,739
  • 6
  • 44
  • 74
14
votes
3 answers

How to get the child declaring type from an expression?

I have a Parent / Child class hierarchy where the Parent abstractly declares a string property and the Child class implements it: abstract class Parent { public abstract string Value { get; } } class Child : Parent { public override string…
Trinition
  • 1,153
  • 2
  • 15
  • 25
14
votes
2 answers

Why use #' with lambda?

Why should I use #' together with lambda? It is usually written that way, so I guess it is good form. But these lines seem equal to me: > (mapcar #'(lambda (x) (+ x 1)) '(1 2 3)) (2 3 4) > (mapcar (lambda (x) (+ x 1)) '(1 2 3)) (2 3 4) Anyone care…
Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
14
votes
5 answers

Is there any way to pass the lambda expression as a variable or argument?

I need to pass the lambda query as a parameter, the followings code is sample and I am interesting to find an implement for it, there is samples: some thing like this: var expr1 = Where(n => n > 6).OrderBy(n => n % 2 == 0).Select(n => n); var expr2…
Saeid
  • 13,224
  • 32
  • 107
  • 173
14
votes
5 answers

Haskell: where clause referencing bound variables in lambda

I am trying to numerically integrate a function in Haskell using the trapezoidal rule, returning an anti-derivative which takes arguments a, b, for the endpoints of the interval to be integrated. integrate :: (Float -> Float) -> (Float -> Float ->…
Bylextor
  • 213
  • 3
  • 7
14
votes
4 answers

What does the Expression> declaration mean?

Could somebody explain the following declaration in a way that conveys the meaning of the expression and how it would be called? void Delete(Expression> expression) where T : class, new(); I read it as: Delete an object of type T,…
Brendan
  • 1,486
  • 3
  • 19
  • 27
14
votes
2 answers

Is std::bind still useful compared to lambdas?

Possible Duplicate: Bind Vs Lambda? My use of std::bind had dropped to 0 now that lambdas have gained wide support. Are there any problems that std::bind is uniquely suited for over a lambda function? Was there a compelling reason to keep…
deft_code
  • 57,255
  • 29
  • 141
  • 224
14
votes
3 answers

C++ std::function cannot find correct overload

Consider the following case: void Set(const std::function &fn); void Set(const std::function &fn); Now calling the function with Set([](int a) { //... }); Gives "ambiguous call to overloaded function" error. I am…
Cem Kalyoncu
  • 14,120
  • 4
  • 40
  • 62
14
votes
2 answers

botocore package in lambda python 3.9 runtime return error: "cannot import name "'DEPRECATED_SERVICE_NAMES'" from 'botocore.docs'"

I am using Lambda Python 3.9 runtimes. I also use boto3 and botocore default packages in Lambda. Today, I suddenly got this error: "cannot import name "'DEPRECATED_SERVICE_NAMES'" from 'botocore.docs'". I only succeeded in fixing it when I added the…
Elad Hazan
  • 171
  • 1
  • 3
  • 5
14
votes
1 answer

Is it valid to create closure (lambda) objects using `std::bit_cast` in C++20?

A colleague showed me a C++20 program where a closure object is virtually created using std::bit_cast from the value that it captures: #include #include class A { int v; public: A(int u) : v(u) {} auto getter() const {…
Fedor
  • 17,146
  • 13
  • 40
  • 131
14
votes
2 answers

Can 'auto' be used as a subtype of lambda argument in C++?

C++ code with auto as a part of lambda argument type is accepted by GCC, e.g.: #include #include int main() { auto make_vector = []( std::initializer_list v ) { return std::vector
Fedor
  • 17,146
  • 13
  • 40
  • 131
14
votes
1 answer

Dispatcher.BeginInvoke , trying to use lambda to get string set from textblock, but getting conversion error

I am trying to call a selected listbox item from a button, not the listbox.selecteditemchanged method in wpf. So when i try string yadda = listbox.SelectedItem.ToString(); i get an exception: The calling thread cannot access this object because a…
darthwillard
  • 809
  • 2
  • 14
  • 28
14
votes
2 answers

Objective-C code blocks equivalent in C#

How would I write the equivalent code in C#: typedef void (^MethodBlock)(int); - (void) fooWithBlock:(MethodBlock)block { int a = 5; block(a); } - (void) regularFoo { [self fooWithBlock:^(int val) { NSLog(@"%d", val); …
user204884
  • 1,745
  • 2
  • 19
  • 27
1 2 3
99
100