[IronPython] Lamba Expressions in IronPython

Ben Hall ben2004uk at googlemail.com
Mon Apr 7 02:26:57 CEST 2008


Thank you for all the answers, made everything make a lot more sense :)

Cheers

Ben

On Mon, Apr 7, 2008 at 1:03 AM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Ben Hall wrote:
> > Hi everyone,
> >
> > Just been playing around with C# and IronPython interop and I wanted
> > to define a lambda expression.
> >
> > My CLR object is just a wrapper around a generic list (as generics
> > aren't supported?)
> >
> > public class GenericWrapper : List<int>
> > {}
> >
> > I tried to do a lamba expression to pull back a item from the
> > collection, however I got the following exception:
> >
> >>>> i = GenericWrapper()
> >>>> i.Add(1)
> >>>> i.Add(2)
> >>>> i.Add(3)
> >>>> v = i.Find(item => item == 1)
> >>>>
> >   File "", line 1
> >     v = i.Find(item => item == 1)
> >
>
> lambda item: item == 1
>
> In general, arbitrary C# syntax doesn't "just work" with IronPython and
> you have to stick to Python syntax. ;-)
>
> (However, if "Find" expects a particular type of delegate you may have
> to use CallTarget0 or create a delegate).
>
> Michael
> http://www.ironpythoninaction.com
>
> >                      ^
> > SyntaxError: unexpected token '>'
> >
> > I guess I can use a method\delegate like in C# 2.0, but is there any
> > way to do anything like Lamba Expressions?  Or is there something
> > similar in Python?
> >
> > Any help would be great.
> >
> > Thanks
> >
> > Ben
> > Blog.BenHall.me.uk
>
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



More information about the Ironpython-users mailing list