This post originated from an RSS feed registered with Agile Buzz
by Keith Ray.
Original Post: More Python Multiple-Returns
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
John Roth, via email, tells me that "multiple-return" like this:
quotient, remainder = divmod(divisor, dividend)
is actually a syntactic short-cut for this:
result = divmod(divisor, dividend)
quotient = result[0]
remainder = result[1]
The divmod function returns a tuple (an immutable list) and the language automatically unpacks it for you. When I wrote my earlier blog entry, I actually did think of the this "divmod" function... except I couldn't recall the exact name (almost remembered the Forth equivalent, useless in this context), and I was, of course, too lazy to look it up in the Python docs.
Once on comp.lang.smalltalk, there was a discussion on how hard it would be to add increment-assignment to Squeak's Smalltalk compiler. Someone posted the actual code, and it was only a few short modified methods. I expect that automatic-unpacking, ala Python "Multiple-Returns", would also be a small modification to the compiler, that most Smalltalk environments could support each in their own way.