The end to all language wars and the great unity API to come!
rantingrick at gmail.com
Tue Jul 5 18:35:01 EDT 2011
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
> 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, y)), what happens?
So are you suggesting that a control structure must have at minimum
one of "for", "while", or "if"? Okay, i listening. Go on...
> We'll call that argument srt, here's a sample (naive) implementation:
> def sort(key):
> lst = self.internal_list
> for n in range(len(self.internal_list) - 1):
> for i in range(len(self.internal_list) - 1):
> if srt(lst[i], lst[i+1]) < 0:
> lst[i], lst[i+1] = lst[i+1], lst[i]
> See what's in there? An if.
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. Interesting Corey, very
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). It doesn't matter that the code is contained in a function
object. That's like saying a cake is not a cake because it was
packaged in a shoe box instead of a cake box.
> Sure, WHAT the if does is user-controlled with the
Well as long as you can admit that fact.
> but that doesn't make that particular if a new control structure,
Oh i see. Change the rules as we go eh?
> it certainly doesn't make the key a control structure. You can pass a key
> to a sort even in C and that certainly doesn't have user defined control
What the hell does C have to do with Python Corey? One thing is for
sure, i always get a giggle from your self defeating posts. You're the
best enemy a person could have. Thank you. *bows*
More information about the Python-list