views:

320

answers:

6

I have had recently two telephone interviews.

In both of them I have been asked what is Lambda expression as the last question.

Well I said that Lambda expression is an unnamed method in place of a delegate. But somehow that wasn't enough.

I find it very hard to explain this precisely on a telephone interview.

Does anyone know better?

UPDATE: Sorry i just have realized my question was not right. The question was refering to Lambda expression. I think I ruined the question already. Sorry again! I have updated the question.

Thanks,

+1  A: 

Maybe they just wanted to hear that LINQ was "Language-Integrated Query".

That being said, if they really want an explanation of "what" LINQ is comprised of, I would have probably included more information that you provided. Something like:

LINQ, or Language-Integrated Query, is a set of language additions and framework classes added in .NET 3.5 which enable a more functional approach to query operations. It's based upon extension methods for IEnumerable and IQueryable and their generic counterparts which allow deferred execution in LINQ to Objects and remote processing via IQueryable, as well as many other features. There were also language changes made to C# and VB.NET to support a more "natural" query syntax directly in the language.

Reed Copsey
A: 

They're probably looking for you to know that LINQ is the new DSL for querying IQueryable and IEnumerable objects. The "from ... where ... select ..." syntax, essentially. Knowing that it's implemented under-the-covers with lambdas and functional style would probably get you bonus points.

Mark
+1  A: 

Well I said that Linq is an unnamed method in place of a delegate.

Actually, that's not LINQ at all, but a "lambda expression". And technically, LINQ doesn't even use them.

LINQ stands for "Language Integrated Query". Quite specifically, it's the "from...where.. select" keywords (i.e., the query syntax that is integrated into the language).

Now, to get those keyword to do things, a lot more was added to the language (and the CLR) (such as lambdas, extension methods, the Enumerable class etc).

James Curran
I just realized I have ruined teh question. You are right. The question shoudl have been Lambda expression. At teh time of writing I had some how LINQ on mind. :(
Kave
+1  A: 

To answer your revised question, for that, you answer is actually good. The only change I'd make is to stress the word "inline".

Lambda expression is an unnamed method that is written inline in place a where a delegate is needed.

James Curran
A: 

A lambda expression is a nameless suspension of code.

Consider this anonymous "multiply two things" function (a.k.a. lambda expression), using some very non-specific notation.

λ(x, y) -> x * y

Your answer was very specific to a place where you've used lambdas (I'm guessing C#?), and I suspect the interviewer was asking for a more general understanding. The concept of a delegate, the language C#, and the idea of a method are all secondary to what a lambda is and how they work. You can compute using lambda expressions on paper, for instance, with no methods involved.

Andres Jaan Tack
+1  A: 

Lambda Expressions are nameless functions given as constant values, and written exactly in the place where it's needed, typically as a parameter to some other function. The canonical example is that you'll pass a comparison function to a generic "sort" routine, and instead of going to the trouble of defining a whole function (and incurring the lexical discontinuity and namespace polution) to describe this comparison, you can just pass a lambda expression describing the comparison.

HOWEVER, this misses one of the most important features of Lambda Expressions, which is that they execute in the context of their appearance. Therefore, they can use the values of the variables that are defined in that context.

Lambda expressions appear (with different syntax) in all LISPs, Perl, Python, and many other languages, but notably not C, Java, or any similar language, even though those all have a way to deal with passing functions (or some excuse for them) around as parameters. They are a syntax element with particular semantics, and those semantics place more requirements on the runtime than C was designed to require.

Ian