On Wed, Aug 01, 2001 at 06:56:17AM +0900, ayumix wrote: > Please make Perl autovivification possible in Ruby. > > foo[obj]="hello" > > (1) If foo is undefined, and if obj is not integer, > Ruby will define foo as hash like foo={} > > (2) If foo is undefined, and if obj is integer, > Ruby will ** assume ** foo is array, > and will define foo as array like foo=[] foo ||= Hash.new foo[obj] = "hello" or class nil def []= (key, value) if key.kind_of? Integer ary = Array.new ary[key] = value return ary else return {key => value} end end not sure about this code - but I think it should be possible to implement it kinda like this... > If I want foo[5] to be hash, I have to declare foo explicitly > foo={} > foo[5]="hello" > > or do it differently > foo[5.to_s]="hello" You are mixing Integers and Strings here. 5 is _NOT_ the same key as 5.to_s > ########## > Is it possible to add C style loop to Ruby? > The following is from "Programming Ruby". > > def fibUpTo(max) > i1, i2 = 1, 1 > while i1 <= max > yield i1 > i1, i2 = i2, i1+i2 > end > end > fibUpTo(1000) { |f| print f, " " } > > C style loop: > > def fibUpTo(max) > for (i1, i2=1, 1; i1<=max; i1, i2=i2, i1+i2) > yield i1 > end > end > fibUpTo(1000) { |f| print f, " " } > > ########## > Please add this cool Python stuff to Ruby. > > If 25 < foo < 75 : print "middle" (25...75).include? foo I think there is enough "syntatik sugar" in ruby.... And I personally don't like this kind of magic perl does in the first example. I'd rather state explicitly what I want, and make my code more readable (and less prone to stupid bugs like assuming foo[obj] will always generate a Hash automatically, while in reality it _sometimes_ generates an array) But if you like this kind of stuff, just build a library which tries to emulate this perl/phyton behaviour, and use it for your projects. You might not be able to to emulate the perl/phyton syntax a 100 percenpt, but you should come pretty close. greetings, Florian Pflug