lambda

Restrictons of Python compared to Ruby: lambda's

Hi, I was going over some pages from WikiVS, that I quote from: because lambdas in Python are restricted to expressions and cannot contain statements I would like to know what would be a good example (or more) where this restriction would be, preferably compared to the Ruby language. Thank you for your answers, comments and fe...

Undefined symbols for C++0x lambdas?

I was just poking around into some new stuff in C++0x, when I hit a stumbling block: #include <list> #include <cstdio> using namespace std; template <typename T,typename F> void ForEach (list<T> l, F f) { for (typename list<T>::iterator it=l.begin();it!=l.end();++it) f(*it); } int main() { int arr[] = {1,2,3,4,5,6}; ...

How to stop ReSharper from showing error on a lambda expression where Action is expected?

In Silverlight, System.Windows.Threading's Dispatcher.BeginInvoke() takes an Action<T> or a delegate to invoke. .NET allows me to pass just the lambda expression. but ReSharper sees it as an error, saying "Cannot resolve method 'BeginInvoke(lambda expression)'": Dispatcher.BeginInvoke(() => { DoSomething(); }) The error goes away if ...

How can I make Church numerals more human readable in lisp?

I can define church numerals fairly easy using scheme: > (define f (lambda (x) x)) > (f f) ;0 #<procedure:f> > (f (f f)) ;1 #<procedure:f> However, this doesn't make it very easy to recognize that (f f) is 0 and (f (f f)) is 1. Is there a way that I can make these numerals more readable? What would be ideal is this: > (f f) 0 > (f ...

Convert Lambda from C# to VB.NET

How would I translate this C# lambda expression into VB.NET ? query.ExecuteAsync(op => op.Results.ForEach(Employees.Add)); using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System....

c# Lambda Expression built with LinqKit does not compile

This lambda does not compile, but I do not understand why. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using LinqKit; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var barModel = new BarModel(); ...

Return nested alias for linq expression

I have the following Linq Expression var tooDeep = shoppers .Where(x => x.Cart.CartSuppliers.First().Name == "Supplier1") .ToList(); I need to turn the name part into the following string. x.Cart.CartSuppliers.Name As part of this I turned the Expression into a string and then split on the . and removed the First() argumen...

Why can't c# use inline anonymous lambdas or delegates?

I hope I worded the title of my question appropriately. In c# I can use lambdas (as delegates), or the older delegate syntax to do this: Func<string> fnHello = () => "hello"; Console.WriteLine(fnHello()); Func<string> fnHello2 = delegate() { return "hello 2"; }; Console.WriteLine(fnHello2()); So why can't I "inline" the lambda o...

C# style Action<T>, Func<T,T>, etc in C++0x

C# has generic function types such as Action<T> or Func<T,U,V,...> With the advent of C++0x and the ability to have template typedef's and variadic template parameters, it seems this should be possible. The obvious solution to me would be this: template <typename T> using Action<T> = void (*)(T); however, this does not accommodate f...

Render Html from a lambda in MVC

I have the following code to generate a list and will allow developers to customize the output if needed. <% Html.List<MyList>(item => item.Property).Value(item => return "<div>" + item.Property + "<br/>" + item.AnotherProperty + "</div>").Render() %> This is not ideal, how can I allow the developers to add the html similar to other c...

Lambda Expressions

Can somebody explain me lambda expressions & what they can be used for. I have googled for it & have a rough idea. most of the examples give c# code. How about lambda expressions in plain old C...? ...

I need to write Linq to SQL Lamda expression query the result of which is IQueryable and i want to use orderby and skip,take extension methods on this result object

I need to write Linq to SQL Lamda expression query the result of which is IQueryable and i want to use orderby and skip,take extension methods on this result object ...

lambda expression based reflection vs normal reflection

What is the difference between normal reflection and the reflection that can be done with lambda expressions such as this (taken form build your own MVVM): public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property) { var lambda = (LambdaExpression)property; MemberExpression memberExpression; if (lamb...

lambda vs. operator.attrgetter('xxx') as sort key function in Python

I am looking at some code that has a lot of sort calls using comparison functions, and it seems like it should be using key functions. If you were to change seq.sort(lambda x,y: cmp(x.xxx, y.xxx)), which is preferable: seq.sort(key=operator.attrgetter('xxx')) or: seq.sort(key=lambda a:a.xxx) I would also be interested in comments ...

Ambiguous call between methods ASP.NET MVC

I'm pretty new in ASP.NET MVC (about 3 months) and i've the followin issue: I have a Entity Class called 'Usuario' in a ClassLibrary referenced as 'Core' and, when i create a strongly-typed view and add a html.textboxfor<> like: <%= Html.TextBoxFor(u => u.Login) %> it raises the following error: Error 3 The call is ambiguous bet...

python function parameter evaluation model

I was looking at an article on Peter Norvig's website, where he's trying to answer the following question (this is not my question, btw) "Can I do the equivalent of (test ? result : alternative) in Python?" here's one of the options listed by him, def if_(test, result, alternative=None): "If test is true, 'do' result, else alterna...

How do I get around this lambda expression outer variable issue?

I'm playing with PropertyDescriptor and ICustomTypeDescriptor (still) trying to bind a WPF DataGrid to an object, for which the data is stored in a Dictionary. Since if you pass WPF DataGrid a list of Dictionary objects it will auto generate columns based on the public properties of a dictionary (Comparer, Count, Keys and Values) my Per...

Lambda Expression to be used in Select() query

Hi, I am trying to build a lambda expression, containing two assignments (as shown further down), that I can then pass to a Queryable.Select() method. I am trying to pass a string variable into a method and then use that variable to build up the lambda expression so that I can use it in a LINQ Select query. My reasoning behind it is ...

How do I return a Database table column using Expression in LINQ?

I want to return a column values dynamically at runtime using Expression<> how can I achieve this? What will be a function to return look like? I found this- http://www.onedotnetway.com/dynamic-sort-with-linq-to-sql/ but GetTable() in visual studio 2010 has no such function...Please help me out..Also I get this exception when using fun...

Linq to SQL DynamicInvoke(System.Object[])' has no supported translation to SQL.

I have a class, Users. Users has a UserId property. I have a method that looks something like this: static IQueryable<User> FilterById(this IQueryable<User> p, Func<int, bool> sel) { return p.Where(m => sel(m.UserId)); } Inevitably, when I call the function: var users = Users.FilterById(m => m > 10); I get the following except...