[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04253] Re: TABWTDI and Hash.new([])

From: Dave Thomas <Dave@...>
Date: 2000-07-28 13:24:07 UTC
List: ruby-talk #4253
Aleksi Niemel<aleksi.niemela@cinnober.com> writes:

> > I seems to me that we could actually do it Perl's way (but better ;-)
> > with not too much each effort.
> 
> How about Arrays? Should they be automatically resized (enlarged)
> when one says:
> 
>   a = Array.new(2, 42, CREATENEWBYDEFAULT) 
>        #=> a = [42, 42]
>   puts a[4]            
>        #=> a = [42,42,42,42,42]

Logically not. The array semantics are different than hash. With
array, you explicitly say in the constructor that you want 'n' copies
of some object 'default'. The CreateNew flag here would not change the 
number of copies. Instead, it would affect whether those _were_
copies, or whether they were new objects.

As a totally separate change, you might want to argue for something
like:

  a = Array.new(0, 42)

meaning that reference to an unset array element returned 42. This
would give you the behavior above.


Regards


Dave

In This Thread

Prev Next