The end to all language wars and the great unity API to come!
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jul 6 07:44:21 EDT 2011
rantingrick wrote:
> On Jul 5, 11:04 am, Corey Richardson <kb1... at aim.com> wrote:
>
>> How is giving the sort method a function by which to determine the
>> relative value of objects a control structure? Do you know what a control
>> structure is? It's something that you use to modify control flow:
>>
>> if foo <= bar:
>> foo += 1
>> else:
>> bar += 1
>
> Interesting, corey. Very interesting. However the fun is yet to come
> so stay tuned...
>
>> That's a control structurem the "if-else". I don't know what Ruby calls a
>> control structure, but that's what it is. for and while are in there too.
>> When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens?
>
> So are you suggesting that a control structure must have at minimum
> one of "for", "while", or "if"?
A control structure is a structure which controls the program flow. Control
structures include:
* jumps (goto, gosub, comefrom, exceptions, break, continue)
* loops (for, while, repeat...until)
* conditional branches (if, case/switch)
There may be others, although I can't think of any of hand. Jumping, looping
and branching pretty much covers all the bases, I think.
It excludes expressions such as ternary-if, because that doesn't control
program flow, it's just an expression.
A function which includes a control structure inside it is not itself a
control structure, in the same way that the existence of bones inside you
does not make you a bone.
[...]
> Yes there IS and "if" in there and IF you look closely enough you may
> see two "for"'s also. So by your own definition this (naive) code
> qualifies as a control structure.
I see what you did there. First you put words into Cory's mouth that he did
not say, they you try to criticise him based on those words -- YOUR words.
No Rick, that's your definition, not Cory's. Please do not treat us as
stupid.
> But wait just a second Corey. My statement has nothing to do with
> sort. sort is just the vehicle. My statement is that the cmp argument
> to sort IS a user defined control structure (the code block to be
> exact).
The cmp argument to sort is not a control structure because it is not a
structure and it does not control the program flow.
--
Steven
More information about the Python-list
mailing list