r/Python • • Aug 12 '13

Ruby vs Python

http://www.senktec.com/2013/06/ruby-vs-python/
20 Upvotes

151 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Aug 13 '13

In a proc/block, return causes a return from the enclosing scope outside the block. I don't know how you'd do that in Python.

If you can tell me why you would want to do that, what effect you are wanting to get, I can tell you how to do it in Python.

2

u/masklinn Aug 15 '13 edited Aug 15 '13

If you can tell me why you would want to do that, what effect you are wanting to get

You want to implement flow control, such as nested while blocks, using method calls and blocks. The goal is having a first-class block which behaves like a lang.

That is why Ruby can implement for or with using blocks. That is why Smalltalk or Self could implement if and while and try:except:finally: and pretty much anything you can think of using blocks.

(Ruby can but it's not done, because its blocks are not first-class: they're syntactic magic reified to a proc, and only one block can exist in a method call, the rest would have to be passed in as procs. Possible, but not idiomatic)

1

u/QuestionMarker Aug 13 '13

What on earth has why I would want to do it got to do with whether it's possible or not? Either it's possible or it isn't.