C#3.0 and lambdas
Steve Holden
steve at holdenweb.com
Wed Sep 21 16:11:38 CEST 2005
Christophe wrote:
> 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.
>
This is rubbish.
foo(*p1)
is *exactly* equivalent to
foo(p1[0], p1[1])
and similarly
bar(p2)
is *exactly* equivalent to
bar(p2[0], p2[1])
and consequently the second version of drawline is exactly equivalent to
the first. So, if the second one is useless then so is the first.
> And what about a function which computes the line length ?
I'm not sure what point you are trying to make here. Can you explain?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
More information about the Python-list
mailing list