Re: RFC 170 (v1) Generalize =~ to a special-purpose assignment operator

2000-08-30 Thread Bart Lateur

On 30 Aug 2000 02:07:24 -, Perl6 RFC Librarian wrote:

>Generalize =~ to a special-purpose assignment operator

Personally, I think of it as the "apply to" operator, as opposed to the
"assign to" operator:

=   assign the RHS to the LHS
=~  apply the RHS to the LHS


perlop calls it a "binding operator". That's fine too, apart from this
error in perlop:

Binary "=~" binds a scalar expression to a pattern match.

I'm sorry, but it applies to tr/// too, and that IS NOT a pattern match.

-- 
Bart.



Re: RFC 170 (v1) Generalize =~ to a special-purpose assignment operator

2000-08-29 Thread Matthew Cline

On Tue, 29 Aug 2000, Nathan Wiger wrote:

> David Nicol and I were brainstorming offline, and came up with a cool
> extension: ~=. These new operator would do a similar thing to =~ as
> described by the RFC, only LEFT padding the args:
>
> $stuff =~ dojunk(@args);   # $stuff = dojunk(@args, $stuff);
> $stuff ~= dojunk(@args);   # $stuff = dojunk($stuff, @args);
>
> The position of the ~ tells you how args are filled in: if it's on the
> left, then they're filled in to the left. If they're on the right, then
> they're filled in to the right. Quite flexible, IMO.

This would be bad for someone reading the code, as it would take
extra concentration to tell a "~=" from a "=~"; right now, a
"=" with a "~", I just know what it is, without having to determine
the order.

-- 
Matthew Cline| Suppose you were an idiot.  And suppose that
[EMAIL PROTECTED] | you were a member of Congress.  But I repeat
 | myself.  -- Mark Twain



Re: RFC 170 (v1) Generalize =~ to a special-purpose assignment operator

2000-08-29 Thread Nathan Wiger

> This RFC proposes a simple use for C<=~>: as a last-argument rvalue
> duplicator. What this means is that an expression such as this:
> 
>$value = dostuff($arg1, $arg2, $value);
> 
> Could now be rewritten as:
> 
>$value =~ dostuff($arg1, $arg2);

David Nicol and I were brainstorming offline, and came up with a cool
extension: ~=. These new operator would do a similar thing to =~ as
described by the RFC, only LEFT padding the args:

$stuff =~ dojunk(@args);   # $stuff = dojunk(@args, $stuff);
$stuff ~= dojunk(@args);   # $stuff = dojunk($stuff, @args);

The position of the ~ tells you how args are filled in: if it's on the
left, then they're filled in to the left. If they're on the right, then
they're filled in to the right. Quite flexible, IMO.

-Nate



RFC 170 (v1) Generalize =~ to a special-purpose assignment operator

2000-08-29 Thread Perl6 RFC Librarian

This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Generalize =~ to a special-purpose assignment operator

=head1 VERSION

   Maintainer: Nathan Wiger <[EMAIL PROTECTED]>
   Date: 29 Aug 2000
   Mailing List: [EMAIL PROTECTED]
   Version: 1
   Number: 170
   Status: Developing
   Requires: RFC 164

=head1 ABSTRACT

Currently, C<=~> is only available for use in specific builtin pattern
matches. This is too bad, because it's really a neat operator.

This RFC proposes a simple way to make it more general-purpose.

=head1 DESCRIPTION

First off, this assumes RFC 164. Second, it requires you drop any
knowledge of how C<=~> currently works. Finally, it runs directly
counter to RFC 139, which proposes another application for C<=~>.

This RFC proposes a simple use for C<=~>: as a last-argument rvalue
duplicator. What this means is that an expression such as this:

   $value = dostuff($arg1, $arg2, $value);

Could now be rewritten as:

   $value =~ dostuff($arg1, $arg2);

And C<$value> would be implicitly transferred over to the right side as
the last argument. It's simple, but it makes what is being operated on
very obvious.

This enables us to rewrite the following constructs:

   ($name) = split /\s+/, $name;
   $string = quotemeta($string);
   @array = reverse @array;
   @vals = sort { $a <=> $b } @vals;

   $string = s/\s+/SPACE/, $string;# RFC 164
   $matches = m/\w+/, $string; # RFC 164
   @strs = s/foo/bar/gi, @strs;# RFC 164

As the shorter and more readable:

   ($name) =~ split /\s+/;
   $string =~ quotemeta;
   @array =~ reverse;
   @vals =~ sort { $a <=> $b };

   $string =~ s/\s+/SPACE/;# looks familiar
   $string =~ m/\w+/;  # this too [1]
   @strs =~ s/foo/bar/gi;  # cool extension

It's a simple solution, true, but it has a good amount of flexibility
and brevity. It could also be the case that multiple values could be
called and returned, so that:

   ($name, $email) = special_parsing($name, $email);

Becomes:

   ($name, $email) =~ special_parsing;

Again, it's simple, but seems to have useful applications.

=head1 IMPLEMENTATION

Simplistic (hopefully).

=head1 MIGRATION

This introduces new functionality, which allows backwards compatibility
for regular expressions. As such, it should require no special
translation of code. This RFC assumes RFC 164 will be adopted (which it
may not be) for changes to regular expressions.

True void contexts may also render some parts of this moot, in which
case coming up with a more advanced use for C<=~> may be desirable.

=head1 NOTES

[1] That m// one doesn't quite work right, but that's a special case
that I would suggest should be caught by some other part of the grammar
to maintain backwards compatability (like bare //).

=head1 REFERENCES

RFC 164: Replace =~, !~, m//, and s/// with match() and subst()

RFC 139: Allow Calling Any Function With A Syntax Like s///