[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lhs and rhs in table.sort
- From: iain morland <iain@...>
- Date: Wed, 26 Aug 2015 21:44:40 +0100
Thank you for the further responses. I now see that rhs/lhs was a red herring!
Unfortunately I still don’t confidently grasp how the function works. Take the example in Roberto’s PiL book:
table.sort(network, function(a,b) return (a.name > b.name) end)
Presumably the function in the second argument returns true or false - right? Either a.name is greater than b.name or not.
But what are a and b? Does table.sort repeatedly call the function using successive pairs of items from the table ‘network’ as arguments a and b?
And if the arguments passed to this function refer to a *different* table from that which is being sorted, where (in memory) is the sorting occurring? The other table doesn’t get sorted in-place, for its order remains the same.
I think the crux of my confusion is that the function in the second argument iterates, but it doesn’t look like an iterator - at least to the less trained reader.
Thanks
Iain