On Thursday, May 9, 2002, at 03:16 PM, Aaron Sherman wrote: > Then you can declare them as such: > > sub get_bar() { .bar } > sub get_baz() { .baz } > sub set_baz($newbaz) { .baz = $newbaz }
Seeing this, an idea mildly Eiffel-ish comes to mind. Could we get away with something like the following? method set_baz(type($.baz) $newbaz) { $.baz = $newbaz } Which would force the new value to be of the same type as the current value, without having to strongly declare the type of the variable elsewhere. Sort of like, in Perl5... sub set_baz { my $self = shift; if (@_) { my $new_baz = shift; $new_baz_type = ref($new_baz) || "SCALAR"; $current_baz_type = ref($self->{baz}) || "SCALAR"; $self->{baz} = new_baz if $new_baz_type eq $current_baz_type; } return $self->{baz}; } or in Eiffel... set_baz(new_baz: like baz) is do baz := new_baz end