Hi,

In message "[ruby-talk:13054] Questions about ruby"
    on 01/03/22, Roy Patrick Tan <rtan / vt.edu> writes:

|1. blocks: differences with Smalltalk. If you want to pass blocks in 
|Smalltalk, it seems to need to be explicitly declared in the method 
|definition, ie to implement a to:do: method, you'd have to do something 
|like:
|
|to: n do: code |index|
|    ...
|
|While in Ruby, you need to do
|def upto(n)
|     ...
|     yield index
|
|Does calling the yield statement create sort of an implicit parameter 
|for the method?

Invoking a method with a block is something like giving it an implicit
argument.  "yield" evaluate this hidden parameter.

|2. blocks and closures
|I am a bit confused about the term "closure" used in the pickaxe book. 
|It seems to me that "closure" means that a block is a Proc object, and 
|can retain the context of where it is defined. This looks like Proc is 
|more or less equivalent to the Scheme "lambda"... is this correct? Why 
|is this property called "closure"? Further, though blocks can be Procs, 
|can methods also be Procs?

The answer are the first question is yes.  And you might have noticed
we have "lambda" method aliased to "Proc.new".  The only difference is
lambda creates unnamed function with its context, meanwhile proc
creates the object associated to lines of code with its context.

The reason why they are called "closures" is they pack their
environment (e.g. local variable bindings) together with the code to
execute.

Lastly, methods can be Procs by using "to_proc" method.

  self.method(:print).to_proc.call("hello\n")

|3. In the "Programming Ruby" DDJ article, Dave and Andy say that Ruby is 
|a pure OO language, but they also say that *just about* everything in 
|Ruby is an object. What are not objects in Ruby? Does Ruby having 
|control structures that are not methods make it less pure an OO language?

Variables, blocks, control structures are not objects in Ruby.

And I believe control structures by methods make a language have less
rules, but don't make it less OO.

							matz.