A replacement for lambda

Kay Schluehr kay.schluehr at gmx.net
Sat Jul 30 03:02:41 EDT 2005


Tim Roberts schrieb:

> Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
> >
> >What kind of shenanigans must a parser go through to translate:
> >     <x**2 with(x)><<x**3 with(x)>
> >
> >this is the comparison of two functions, but it looks like a left-
> >shift on a function until the second with is encountered.  Then
> >you need to backtrack to the shift and convert it to a pair of
> >less-thans before you can successfully translate it.
>
> C++ solves this exact problem quite reasonably by having a greedy
> tokenizer.  Thus, that would always be a left shift operator.  To make it
> less than and a function, insert a space:
>     <x**2 with(x)>< <x**3 with(x)>
> --
> - Tim Roberts, timr at probo.com
>   Providenza & Boekelheide, Inc.

Python does have such a greedy/longest match tokenizer too:

>>> 2 .__add__(3)   # insert whitespace before dot
5

>>> 2.__add__(3)    # 2. is a float
-> Exception

Kay




More information about the Python-list mailing list