[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6681] Re: each/for binding confusion and resolution

From: grady@... (Steven Grady)
Date: 2000-11-30 18:10:02 UTC
List: ruby-talk #6681
hipster responds:
>Would, a construct similar to Thread.new,
>
>	proc([arg*]) { |args| block } -> aProc
>
>reduce the surprise? (I may overlook some binding semantics here, just
>an idea)

Interesting.

I'm not sure if you meant that the "arg*" list would be passed on
as the block's "args" list.  If so, there's a problem, because blocks
already take a set of arguments.  An alternative interpretation is simply
that the arguments of proc() are to be used locally (i.e. the block
gets their value, not the variable itself).

One of my original questions was whether you could achieve
my intent using a <for> loop instead of an <each> iterator.
Using the above syntax (with my alternative semantics), it would
be something like:
    procs = []
    for v in [1, 2]
	procs << proc(v) { v }
    end

By putting the "v" in the argument list of proc(), I am indicating that
the v should be derefenced now, rather than when the Proc is called.

This would also address the scoping problem.  So even if v had been
previously defined, you could still do this with <each>:
    v = nil		# Note that this prevents v from being block-local
    procs = []
    [1, 2].each {|v|
	procs << proc(v) { v }
    }

Unfortunately, I'm guessing there is no way to reimplement such a change
within Ruby; Proc.new would have to be changed inside the interpreter.
(Perhaps it could be done in Ruby if the Binding class had instance methods
to modify the bindings, but that's a mere dream..)
--
	Steven
"You're going to wish you never heard the name `Santa'."

In This Thread

Prev Next