[#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:6680] Re: each/for binding confusion and resolution

From: grady@... (Steven Grady)
Date: 2000-11-30 17:40:02 UTC
List: ruby-talk #6680
Clemens Hintze responds:
>>     Is this the right way to fix the problem?  It apparently imposes
>>     some overhead in that there is a binding stored with each proc,
>
>Yes! But the binding is stored anyway! Blocks will refer to the parent
>context, whether you use it or not, AFAIK!

The other overhead is the binding look-up every time through the loop.
If there were a way of indicating that I wanted the look-up done
just once, when the proc was defined, then the proc would execute more
quickly when it was called. This could have a non-trivial impact if
it were in a tight loop.

>>     and a binding resolution occurs each time the proc is called.  I
>>     think I'd be happier to have a way of specifying that I want the
>>     _value_ of "v", analogous to the #{} notation in double-quoted
>>     strings.  Is there a straightforward way to fix the code that
>>     uses a <for> loop, rather than an <each> iterator?  I don't need
>>     it, but it would be interesting to know of alternate solutions.
>
>POLS. As you already mentioned: use #{} ;-)
>
>  procs = []
>  for v in [1, 2]
>    procs << eval("proc { #{v} }")
>  end
>  procs.collect { |p| p.call }     -> [1, 2]

The problem is that this only works if v's string form is evaluatable.
In my example, v takes in Fixnum values, so your solution works fine.
But in the general case (say, when v holds Method objects), using
eval won't work.
--
	Steven
"That's so deep, I'm getting the bends.... If you want me, I'll
be in the decompression chamber."

In This Thread

Prev Next