A
Aldric Giacomoni
This is something I don't understand, and did not understand when I
studied LISP. I just watched Dave Thomas' presentation, "Extending Ruby
for Fun and Profit", which I by the way highly recommend to everyone who
hasn't seen it...
And he has the following example:
def proc_with_enclosing_scope
name = "Ruby"
lambda { puts name }
end
the_proc = proc_with_enclosing_scope
the_proc.call
name = "Java"
the_proc.call
_____
I don't understand what Ruby is doing / what happens.
First question: the "name" variable is defined inside the method
proc_with_enclosing_scope, so why would changing the name outside the
method make a difference in the first place?
Second question: I tried to type this straight into irb and made a small
typo, so it came out as such -
NoMethodError: undefined method `lamda' for main:Object
from (irb):23:in `proc_with_enclosing_scope'
from (irb):25
So.... When the_proc gets assigned the ... Value of the method
running... (?) What does it get assigned?
And lastly.. I know that "proc" exists, too. What is the difference /
what does it do?
I thank you very much in advance for the enlightenment you will provide
studied LISP. I just watched Dave Thomas' presentation, "Extending Ruby
for Fun and Profit", which I by the way highly recommend to everyone who
hasn't seen it...
And he has the following example:
def proc_with_enclosing_scope
name = "Ruby"
lambda { puts name }
end
the_proc = proc_with_enclosing_scope
the_proc.call
name = "Java"
the_proc.call
_____
I don't understand what Ruby is doing / what happens.
First question: the "name" variable is defined inside the method
proc_with_enclosing_scope, so why would changing the name outside the
method make a difference in the first place?
Second question: I tried to type this straight into irb and made a small
typo, so it came out as such -
NoMethodError: undefined method `lamda' for main:Object
from (irb):23:in `proc_with_enclosing_scope'
from (irb):25
So.... When the_proc gets assigned the ... Value of the method
running... (?) What does it get assigned?
And lastly.. I know that "proc" exists, too. What is the difference /
what does it do?
I thank you very much in advance for the enlightenment you will provide