[#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:6517] Re: Question about the behavior of write attributes in blocks

From: "Christoph Rippel" <chr@...>
Date: 2000-11-22 13:45:21 UTC
List: ruby-talk #6517
Thank you very much for your insightful (and speedy) response.  Is it at all
possible to write an iterator, which allows assignments inside a block?  I
have a vague understanding that the main obstacle is the fact that ``x=y''
does not involve a method invocation.

I played around with the build in iterator for the Array class and came up
with a ``program-let''
**************************************
def surprise(y)
sep="---"
j="A"
for i in y do
   print i+sep
   i  << j        # this is a destructive method - similar to replace
   print i+sep
   i += j
   print i+sep
   i.replace "f"
   print i

   j.succ!
   puts
end
end


dyn =  Array.new(3,"x")
sta = ["x","x","x"]

surprise dyn
puts
surprise sta

**************************************
with a rather surprising  output ...
>>x---xA---xAA---f
>>xA---xAB---xABB---f
>>xAB---xABC---xABCC---f
>>
>>x---xA---xAA---f
>>x---xB---xBB---f
>>x---xC---xCC---f

I am not sure if this is a bug but it certainly violates the ruby principle
of ``least surprise''.   Any thoughts?

Thanks,
        Christoph


In This Thread

Prev Next