Message1889

Author musically_ut
Recipients
Date 2007-09-03.08:05:31
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
A little more exploratory work:

Jython 2.2:

>>>  filter( lambda (x):x==1, [(1,),(2,)] )
[(1,)]

While in Python 2.4:

>>> filter( lambda (x):x==1, [(1,),(2,)] )
[]

In fact, in a simpler example,

In Jython 2.2:

>>> f = lambda (x):x
>>> f(1)
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "<console>", line 1, in <lambda>
TypeError: iteration over non-sequence
>>> f((1,))
1
>>> f((1,2))
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "<console>", line 1, in <lambda>
ValueError: unpack tuple of wrong size
>>> 

While in Python 2.4: 

>>> f = lambda (x):x
>>> f(1)
1
>>> f((1,))
(1,)
>>> f((1,2))
(1, 2)
>>> 

It seems that Jython takes lambda (x) a little too literally, assuming that the argument passed will be only a single element tuple. While Python interprets it like any other function definition.

I will look into the matter further, time permitting.

HTH,
~musically_ut
History
Date User Action Args
2008-02-20 17:18:01adminlinkissue1784950 messages
2008-02-20 17:18:01admincreate