On Wed, Oct 17, 2001 at 07:56:04AM +1000, Damian Conway wrote:
>    > Well, as discussed briefly in an earlier thread, 
>    > http:[EMAIL PROTECTED]/msg08514.html
>    > if we allow ! in function names, we can distinguish between the normal
>    > and in-place versions of functions without proliferating the number of
>    > keywords.
>    > 
>    >     chomp! $string;                        # how chomp() currently works
>    >     my $chomped_string = chomp $string;    # like your chomped() function
> 
> Or, rather than this over-excited syntax, perhaps we could distinguish
> the pure function:
> 
>       chomp $string;          # return a chomped copy of $string
> 
> from the method:
>       
>       chomp $string: ;        # chomp the original $string
>                               # a.k.a. $string.chomp;

That : doesn't really catch the eye well at all.

It seems sort of odd to have a special syntax to disambiguate between
a method call and a function call when we already have syntax to do
so:

    chomp $string;  # function call
    $string.chomp;  # method call.

Leaving that aside, making the method call work in-place and the
function call work not will work *if and only if* it's consistently
applied.  Otherwise it's just going to get confusing to remember which
method versions work like which functions and which don't.

    $string.chomp   # in-place chomp
    @array.sort     # sorts @array directly
    $string.chop    # chops the last character off $string

    my $clean_string = chomp $string;
    my @sorted_array = sort @array;
    my $clean_string = chop $string;

etc...

Also, the methods should return their own objects to allow efficient
chaining (ie. we're not copying, we're aliasing):

    print $string.chomp;

And this should solve the trailing terminator here-doc problem nicely:

    print (<<FOO).chomp;
        blah blah blah
        blah blah more blah
        FOO

Which leaves a small hole.  chop() currently returns the character
chop'd, and chomp() should probably do the same.  But they can't,
since we're already using the return value for something else.

Considering how infrequently the return value of chop() and chomp() is
really used, and how easy it is to emulate the current chop() and
chomp() behavior with substr() and s///, I don't think it'll be a big
loss.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Do you actually think about what you are saying or is it an improvisational 
game of Mad Libs that you play in your head?

Reply via email to