Re: Customizable default hash and array values.

2001-10-08 Thread Michael G Schwern
On Mon, Oct 08, 2001 at 03:23:22PM +0200, Bart Lateur wrote: > On Sat, 6 Oct 2001 19:48:13 -0400, Michael G Schwern wrote: > > >> What about zero. > > > >No problem in Perl 6. > > > >my $foo = %hash{foo} // 'some default'; > > And nobody will ever confuse this operator with the "comment till

Re: Customizable default hash and array values.

2001-10-08 Thread RaFaL Pocztarski
Bart Lateur wrote: > On Sat, 6 Oct 2001 19:48:13 -0400, Michael G Schwern wrote: > > >> What about zero. > > > >No problem in Perl 6. > > > >my $foo = %hash{foo} // 'some default'; > > And nobody will ever confuse this operator with the "comment till end of > line" marker in C++, Java and Jav

Re: Customizable default hash and array values.

2001-10-08 Thread Bart Lateur
On Sat, 6 Oct 2001 19:48:13 -0400, Michael G Schwern wrote: >> What about zero. > >No problem in Perl 6. > >my $foo = %hash{foo} // 'some default'; And nobody will ever confuse this operator with the "comment till end of line" marker in C++, Java and Javascript, and many more I suppose. --

Re: Customizable default hash and array values.

2001-10-06 Thread Michael G Schwern
On Sun, Oct 07, 2001 at 01:26:53AM +0200, Bart Lateur wrote: > > my $foo = $hash{foo} || 'some default'; > > my $bar = $hash{bar} || 'some other default'; > > What about zero. No problem in Perl 6. my $foo = %hash{foo} // 'some default'; -- Michael G. Schwern <[EMAIL PROTECTED]>

Re: Customizable default hash and array values.

2001-10-06 Thread Bart Lateur
On Fri, 28 Sep 2001 21:27:48 +0200, Johan Vromans wrote: >Michael G Schwern <[EMAIL PROTECTED]> writes: > >> so if $key does not exist you'll get 'some default' instead of undef. > >Except that a more common case is > > my $foo = $hash{foo} || 'some default'; > my $bar = $hash{bar} || 'some oth

Re: Customizable default hash and array values.

2001-09-28 Thread Johan Vromans
Michael G Schwern <[EMAIL PROTECTED]> writes: > so if $key does not exist you'll get 'some default' instead of undef. Except that a more common case is my $foo = $hash{foo} || 'some default'; my $bar = $hash{bar} || 'some other default'; -- Johan

Re: Customizable default hash and array values.

2001-09-25 Thread Dan Sugalski
At 10:06 PM 9/24/2001 -0400, Michael G Schwern wrote: >Wouldn't it be nice if there was a way to change the default value of >a hash? So instead of undef you'll get whatever default you like? Sure, I don't see why not. The hash access function is responsible for returning a value, so there's no

Re: Customizable default hash and array values.

2001-09-24 Thread David Grove
I think this is one of many steps in the right direction. Actually, I have a class item defined in my fork as: class foo reserve bar scalar; member bar { default(bar) = '1'; set(bar) = {some code}; get(bar) = {some code}; ensure(bar) = {some code}; confirm(bar) = {some co