C#3.0 and lambdas

Christophe chris.cavalaria at free.fr
Wed Sep 21 09:26:10 EDT 2005


Steve Holden a écrit :
> Christophe wrote:
> 
>> Serhiy Storchaka a écrit :
>>
>>> Roel Schroeven wrote:
> 
> [...]
> 
>>>> or
>>>>
>>>> def drawline(p1, p2):
>>>>    # draw a line from p1[0], p1[1] to p2[0], p2[1]
>>>>    foo(p1[0], p1[1])
>>>>    bar(p2[0], p2[1])
>>>
>>>
>>>
>>> def drawline(p1, p2):
>>>     # draw a line from p1 to p2
>>>     foo(*p1)
>>>     bar(*p2)
>>>
>>
>>
>> That one is stupid. I don't see how you can make it work without some 
>> global storing the p1 information in foo which I would consider as 
>> very ugly code.
> 
> 
> In which case perhaps you should actually try the code. Then once you 
> realise it works you can start to figure out why :-). Hint: f(*p1) 
> appears as len(p1) separate arguments to the called function.

You should also notice that foo knows the starting point of the line but 
not the ending point and so it can't draw the line. On the other hand, 
bar knows the end point but not the starting point so it can't do the 
job either.

And what about a function which computes the line length ?



More information about the Python-list mailing list