Merge procs

okay, i’ve been staring blankly at this thing for almost 2 days now. i
can’t seem to think of a solution.

the problem i’m having can be solved if i can get two seperate Procs to
execute under the same scope:

p = Proc.new {
x = 10
}

q = Proc.New {
puts “i know what x is #{x}”
}

r = p + q # how?

in general my problem is that i need to keep one processes seperate so
that it is reusable.

~transami

Hello –

okay, i’ve been staring blankly at this thing for almost 2 days now. i
can’t seem to think of a solution.

the problem i’m having can be solved if i can get two seperate Procs to
execute under the same scope:

p = Proc.new {
x = 10
}

q = Proc.New {
puts “i know what x is #{x}”
}

r = p + q # how?

If x comes into scope before the procs are defined, they can both
see x:

x = nil
pr1 = proc { x = 10 }
pr2 = proc { puts “x is #{x}” }

pr1.call
pr2.call # x is 10

in general my problem is that i need to keep one processes seperate so
that it is reusable.

I don’t follow that – ?

David

···

On Sat, 27 Jul 2002, Tom Sawyer wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

okay, i’ve been staring blankly at this thing for almost 2 days
now. i can’t seem to think of a solution.

the problem i’m having can be solved if i can get two seperate
Procs to execute under the same scope:

They act as closures, so this is generally possible.

x = 10
p = proc { x }
q = proc { 2 * x }
p p.call + q.call

However, in your example, x is local to the first proc.

Also, you might be able to use a Binding, and pass it to eval.

in general my problem is that i need to keep one processes seperate
so that it is reusable.

What do you mean?

···

On Saturday 27 July 2002 07:45 am, Tom Sawyer wrote:


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE